Skip to content

Remove unnecessary bounds on Error and Display implementations for TryLockError and PoisonError. #31589

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

Merged
merged 1 commit into from
Feb 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/libstd/sys/common/poison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<T> fmt::Display for PoisonError<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send + Reflect> Error for PoisonError<T> {
impl<T: Reflect> Error for PoisonError<T> {
fn description(&self) -> &str {
"poisoned lock: another task failed inside"
}
Expand Down Expand Up @@ -158,14 +158,17 @@ impl<T> fmt::Debug for TryLockError<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send + Reflect> fmt::Display for TryLockError<T> {
impl<T> fmt::Display for TryLockError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.description().fmt(f)
match *self {
TryLockError::Poisoned(..) => "poisoned lock: another task failed inside",
TryLockError::WouldBlock => "try_lock failed because the operation would block"
}.fmt(f)
Copy link
Member

Choose a reason for hiding this comment

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

How come this can't continue to delegate to the same implementation? It seems unfortunate to have to duplicate this with description above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling into the Error implementation via description would require adding a Reflect bound, which is not really needed here.

Copy link
Member

Choose a reason for hiding this comment

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

But you can't have an instance of TryLockError<T> where T isn't Reflect, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're dealing with a generic TryLockError<T> you would have to include the Reflect bound, which is annoying and impossible on stable, where you'd have to bound by Any, which is unnecessarily restrictive. You could do where TryLockError<T>: Display but this is also annoying if you have already asserted T: Display elsewhere.

EDIT: Actually under this definition you don't need any bounds on T, so that last line is wrong.

}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Send + Reflect> Error for TryLockError<T> {
impl<T: Reflect> Error for TryLockError<T> {
fn description(&self) -> &str {
match *self {
TryLockError::Poisoned(ref p) => p.description(),
Expand Down