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

Ensure Guard types impl Display & Debug #42822

Merged
merged 1 commit into from
Jun 23, 2017

Conversation

ChrisMacNaughton
Copy link
Contributor

@ChrisMacNaughton ChrisMacNaughton commented Jun 22, 2017

Fixes #24372

@rust-highfive
Copy link
Collaborator

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.

@@ -393,6 +393,19 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Mutex<T> {
}
}

#[unstable(feature = "std_display", issue = "24372")]
Copy link
Member

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.

Copy link
Contributor Author

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!

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),
Copy link
Member

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 animplforDisplay`

Copy link
Contributor Author

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

@frewsxcv frewsxcv added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 22, 2017
@frewsxcv
Copy link
Member

Weird that these are supposedly missing Debug impls, since we have #![deny(missing_debug_implementations)] at the libcore root

Copy link
Member

@alexcrichton alexcrichton left a 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!

@@ -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> {
Copy link
Member

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?

Copy link
Contributor Author

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 Displayed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nevermind

#[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)
Copy link
Member

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?

#[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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

@@ -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> {
Copy link
Member

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.

@alexcrichton alexcrichton added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 22, 2017
@alexcrichton alexcrichton assigned alexcrichton and unassigned brson Jun 22, 2017
@Mark-Simulacrum
Copy link
Member

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 Fixes #xxx, that way GitHub will automatically close the issue once this merges.

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 22, 2017
@ChrisMacNaughton
Copy link
Contributor Author

@Mark-Simulacrum Does the PR need to have the Fixes: ### as well, or is it fine for just the commit as now?

@Mark-Simulacrum
Copy link
Member

I believe the PR description needs to have it; you should be able to edit it.

@ChrisMacNaughton
Copy link
Contributor Author

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

@sfackler
Copy link
Member

I fixed it up for you!

@ChrisMacNaughton
Copy link
Contributor Author

thanks @sfackler 😂 Didn't realize that the first comment ends up being the PR description

@alexcrichton
Copy link
Member

@bors: r+

Thanks @ChrisMacNaughton!

@bors
Copy link
Contributor

bors commented Jun 22, 2017

📌 Commit 14df549 has been approved by alexcrichton

@Mark-Simulacrum
Copy link
Member

@bors rollup

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 22, 2017
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 22, 2017
…excrichton

Ensure Guard types impl Display & Debug

Fixes rust-lang#24372
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 23, 2017
…excrichton

Ensure Guard types impl Display & Debug

Fixes rust-lang#24372
bors added a commit that referenced this pull request Jun 23, 2017
Rollup of 8 pull requests

- Successful merges: #42777, #42783, #42787, #42821, #42822, #42825, #42829, #42833
- Failed merges:
@bors bors merged commit 14df549 into rust-lang:master Jun 23, 2017
@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Jun 23, 2017
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 18, 2023
…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
bors added a commit to rust-lang/miri that referenced this pull request Nov 21, 2023
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
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
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
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants