Skip to content
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

Merged

Conversation

Mark-Simulacrum
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum commented Nov 2, 2016

Fixes #37525.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

Copy link
Contributor

@Stebalien Stebalien left a 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"
Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(unnecessary comma)

None
}
}

Copy link
Contributor

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.

@Mark-Simulacrum
Copy link
Member Author

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 {
Copy link
Contributor

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.

Copy link
Member Author

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.

@@ -1267,6 +1267,38 @@ impl error::Error for TryRecvError {
}
}

#[stable(feature = "mpsc_recv_timeout_error", since = "1.13.0")]
Copy link
Member

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".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 2, 2016
@alexcrichton
Copy link
Member

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 {
Copy link
Contributor

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).

Copy link
Member Author

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.

@rfcbot
Copy link

rfcbot commented Nov 2, 2016

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.

@rfcbot
Copy link

rfcbot commented Nov 11, 2016

🔔 This is now entering its final comment period, as per the review above. 🔔

psst @alexcrichton, I wasn't able to add the final-comment-period label, please do so.

@alexcrichton
Copy link
Member

@bors: r+

Thanks!

@bors
Copy link
Contributor

bors commented Nov 11, 2016

📌 Commit 2af6111 has been approved by alexcrichton

eddyb added a commit to eddyb/rust that referenced this pull request Nov 11, 2016
…or-error-impl, r=alexcrichton

Add Error implementation for std::sync::mpsc::RecvTimeoutError.

Fixes rust-lang#37525.
eddyb added a commit to eddyb/rust that referenced this pull request Nov 12, 2016
…or-error-impl, r=alexcrichton

Add Error implementation for std::sync::mpsc::RecvTimeoutError.

Fixes rust-lang#37525.
bors added a commit that referenced this pull request Nov 12, 2016
@bors bors merged commit 2af6111 into rust-lang:master Nov 12, 2016
@Mark-Simulacrum Mark-Simulacrum deleted the mpsc-recvtimeouterror-error-impl branch December 27, 2016 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants