-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Ensure Guard types impl Display & Debug #42822
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/libstd/sync/mutex.rs
Outdated
@@ -393,6 +393,19 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> { | |||
} | |||
} | |||
|
|||
#[unstable(feature = "std_display", issue = "24372")] |
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.
All of these can be made #[stable(feature = "std_guard_impls", since = "1.20")]
since stability on impls isn't tracked today. I think these will go into 1.20, but I could be 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.
I wasn't sure about the stability markers but I knew it would need something, thanks!
src/libstd/sync/rwlock.rs
Outdated
impl<T: ?Sized + fmt::Display> fmt::Display for RwLock<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self.try_read() { | ||
Ok(guard) => write!(f, "RwLock {{ data: {} }}", guard), |
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.
Is this supposed to be for Display
or Debug? This formatting suggests it's for
Debugbut this is an
implfor
Display`
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'm not 100% satisfied with this representation for Display
, I'm just not sure how it should be given that we could be unable to effectively lock the guard and get at the internal data
Weird that these are supposedly missing |
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.
Looking great, thanks @ChrisMacNaughton!
src/libstd/sync/mutex.rs
Outdated
@@ -393,6 +393,19 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> { | |||
} | |||
} | |||
|
|||
#[stable(feature = "std_guard_impls", since = "1.20")] | |||
impl<T: ?Sized + fmt::Display> fmt::Display for Mutex< T> { |
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.
We tend to prefer Display
for only values that can be losslessy displayed, so perhaps this could be removed?
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.
Without Mutex
being Display
, it's a lot more difficult for MutexGuard
to be Display
as self.__lock
can't be Display
ed
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.
Nevermind
src/libstd/sync/mutex.rs
Outdated
#[stable(feature = "std_guard_impls", since = "1.20")] | ||
impl<'a, T: ?Sized + fmt::Display> fmt::Display for MutexGuard<'a, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.__lock) |
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.
Could this use *
along the lines of (**self).fmt(f)
to do the displaying?
src/libcore/cell.rs
Outdated
#[stable(feature = "std_guard_impls", since = "1.20")] | ||
impl<'a, T: ?Sized + fmt::Display> fmt::Display for Ref<'a, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.value) |
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 might be best implemented as self.value.fmt(f)
as that'll forward formatting flags and such
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.
Will do!
src/libstd/sync/rwlock.rs
Outdated
@@ -330,6 +330,19 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> { | |||
} | |||
} | |||
|
|||
#[stable(feature = "std_guard_impls", since = "1.20")] | |||
impl<T: ?Sized + fmt::Display> fmt::Display for RwLock<T> { |
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.
Like with Mutex
above I think it's ok to remove this one.
I think this is almost ready, if you want to squash commits (I can provide instructions if you'd like) and edit the description so it states |
c5e6810
to
14df549
Compare
@Mark-Simulacrum Does the PR need to have the |
I believe the PR description needs to have it; you should be able to edit it. |
@Mark-Simulacrum I can't seem to update the PR's description, but #24372 (reference) that the issue will close when this PR is merged from the commit message. |
I fixed it up for you! |
thanks @sfackler 😂 Didn't realize that the first comment ends up being the PR description |
@bors: r+ Thanks @ChrisMacNaughton! |
📌 Commit 14df549 has been approved by |
@bors rollup |
…excrichton Ensure Guard types impl Display & Debug Fixes rust-lang#24372
…excrichton Ensure Guard types impl Display & Debug Fixes rust-lang#24372
…r=dtolnay Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls. For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls. It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (rust-lang#38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (rust-lang#42822) with support for `T: Debug + ?Sized` types. I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one. These are changes to (stable) trait impls on stable types so will be insta-stable. `@rustbot` label +T-libs-api
Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls. For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls. It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (rust-lang/rust#38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (rust-lang/rust#42822) with support for `T: Debug + ?Sized` types. I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one. These are changes to (stable) trait impls on stable types so will be insta-stable. `@rustbot` label +T-libs-api
Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls. For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls. It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (rust-lang/rust#38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (rust-lang/rust#42822) with support for `T: Debug + ?Sized` types. I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one. These are changes to (stable) trait impls on stable types so will be insta-stable. `@rustbot` label +T-libs-api
Add T: ?Sized to `RwLockReadGuard` and `RwLockWriteGuard`'s Debug impls. For context, `MutexGuard` has `+ ?Sized` on its `Debug` impl, and all three have `+ ?Sized` on their `Display` impls. It looks like the `?Sized` was just missed when the impls were added (the impl for `MutexGuard` was added in the same PR (rust-lang/rust#38006) with support for `T: Debug + ?Sized`, and `RwLock*Guard`s did allow `T: ?Sized` types already); the `Display` impls were added later (rust-lang/rust#42822) with support for `T: Debug + ?Sized` types. I think this needs a T-libs-api FCP? I'm not sure if this also needs an ACP. If so I can make one. These are changes to (stable) trait impls on stable types so will be insta-stable. `@rustbot` label +T-libs-api
Fixes #24372