-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Error implementation for std::sync::mpsc::RecvTimeoutError. #37527
Add Error implementation for std::sync::mpsc::RecvTimeoutError. #37527
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, implementations of stable traits are always stable so you might as well just mark it so.
fn description(&self) -> &str { | ||
match *self { | ||
RecvTimeoutError::Timeout => { | ||
"channel is currently empty, but more data may become available later" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say something like "timed out waiting on channel"
. The current message doesn't actually say that this is a timeout.
"channel is currently empty, but more data may become available later" | ||
} | ||
RecvTimeoutError::Disconnected => { | ||
"channel is empty, and sending half is closed" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(unnecessary comma)
None | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're also going to need a Display
implementation.
0aa39b4
to
63d2fc4
Compare
Fixed review comments. |
@@ -1267,6 +1267,38 @@ impl error::Error for TryRecvError { | |||
} | |||
} | |||
|
|||
#[stable(feature = "mpsc_recv_timeout_error", since = "1.13.0")] | |||
impl fmt::Display for RecvTimeoutError { | |||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this be reduced now to self.description().fmt(f)
? Though, I would think you'd want to write something like RecvTimeoutError(<message here>)
instead of the bare message.
I notice that both of these comments also apply to std::sync::mpsc::{RecvError, TryRecvError}
so maybe they are wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm not sure either. That does seem reasonable; I'm happy to change all three to this format if that's what needs to be done.
63d2fc4
to
79d18d0
Compare
@@ -1267,6 +1267,38 @@ impl error::Error for TryRecvError { | |||
} | |||
} | |||
|
|||
#[stable(feature = "mpsc_recv_timeout_error", since = "1.13.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will need to be "1.14.0".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
79d18d0
to
2af6111
Compare
Looks great to me, thanks @Mark-Simulacrum! @rfcbot fcp merge |
#[stable(feature = "mpsc_recv_timeout_error", since = "1.14.0")] | ||
impl fmt::Display for RecvTimeoutError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write this entire function as self.description().fmt(f)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@durka mentioned this here: #37527 (comment), but since the other implementations for display also duplicate this code, I think it's best to leave this as-is for now. I'll be happy to file another PR (once this lands) deduplicating this code.
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 psst @alexcrichton, I wasn't able to add the |
@bors: r+ Thanks! |
📌 Commit 2af6111 has been approved by |
…or-error-impl, r=alexcrichton Add Error implementation for std::sync::mpsc::RecvTimeoutError. Fixes rust-lang#37525.
…or-error-impl, r=alexcrichton Add Error implementation for std::sync::mpsc::RecvTimeoutError. Fixes rust-lang#37525.
Rollup of 30 pull requests - Successful merges: #37190, #37368, #37481, #37503, #37527, #37535, #37551, #37584, #37600, #37613, #37615, #37659, #37662, #37669, #37682, #37688, #37690, #37692, #37693, #37694, #37695, #37696, #37698, #37699, #37705, #37708, #37709, #37716, #37724, #37727 - Failed merges: #37640, #37689, #37717
Fixes #37525.