Repository navigation
Improve Debug implementations of Mutex and RwLock. - #83561
Merged
Merged
Conversation
They now show the poison flag and use debug_non_exhaustive.
Contributor
|
(rust-highfive has picked a reviewer for you, use r? to override) |
5 tasks done
Member
Collaborator
|
📌 Commit 5402abc has been approved by |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Mar 27, 2021
Rollup of 10 pull requests Successful merges: - rust-lang#79399 (Use detailed and shorter fs error explaination) - rust-lang#83348 (format macro argument parsing fix) - rust-lang#83462 (ExitStatus: print "exit status: {}" rather than "exit code: {}" on unix) - rust-lang#83526 (lazily calls some fns) - rust-lang#83558 (Use DebugStruct::finish_non_exhaustive() in std.) - rust-lang#83559 (Fix Debug implementation for RwLock{Read,Write}Guard.) - rust-lang#83560 (Derive Debug for io::Chain instead of manually implementing it.) - rust-lang#83561 (Improve Debug implementations of Mutex and RwLock.) - rust-lang#83567 (Update rustup cross-compilation docs link) - rust-lang#83569 (Add regression tests for rust-lang#56445) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
taiki-e
pushed a commit
to crossbeam-rs/crossbeam
that referenced
this pull request
Oct 31, 2026
#1350) The Debug impls of ShardedLockReadGuard and ShardedLockWriteGuard (crossbeam-utils/src/sync/sharded_lock.rs:506 and :542 before this change) print `.field("lock", &self.lock)`, which goes through ShardedLock's own Debug impl, and that one calls try_read(). A ShardedLockWriteGuard holds the write lock of every shard, so that try_read() always returns WouldBlock and a write guard always prints ShardedLockWriteGuard { lock: ShardedLock { data: <locked> } } instead of the value its holder has exclusive access to. A read guard takes a second read lock on its own shard just to print itself, and also prints `<locked>` when that attempt fails, for example on Linux while a writer is waiting on that shard. This is the implementation std's RwLock guards had until rust-lang/rust#83561 (Rust 1.53) changed it for the same reason, as rust-lang/rust#57703 had done for MutexGuard. std's guards now use `(**self).fmt(f)` with a `T: ?Sized + fmt::Debug` bound (the `?Sized` came in rust-lang/rust#117138). Do the same here. This matches the Display impls of both guards just below them, which already use `(**self).fmt(f)` with `T: ?Sized`, and makes the guards Debug for unsized T such as `[i32]`, which ShardedLock supports (see the existing unsized_type test). The new guard_debug test checks the output of both guards for a Vec<i32> lock and for a [i32] lock. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This improves the Debug implementations of Mutex and RwLock.
They now show the poison flag and use debug_non_exhaustive. (See #67364.)