-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement Debug
for RwLock
and arc::Weak
#22573
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @huonw (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. 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 CONTRIBUTING.md for more information. |
Maybe you could add an implementation for I wonder if this and use std::cell::RefCell;
fn main() {
let cell = RefCell::new(1);
println!("{:?}", cell);
let _b = cell.borrow_mut();
println!("{:?}", cell);
}
|
Thanks for the patch! |
The same could also work for (a)rc::Weak. I’m just wondering if it is a good idea to acquire these resources just for Debug-printing. |
I added Debug for Mutex and made the changes you suggested to RwLock. I didn’t do that for Weak (possible cycles). |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match self.try_lock() { | ||
Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", *guard), | ||
Err(_) => write!(f, "Mutex {{ <locked> }}") |
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.
This could also test for each variant of Err
as one case is that the mutex is already locked but another case is that the mutex is poisoned (but the lock was successfully acquired).
@nwin looks good to me, thanks! Could you squash the commits together as well? Also feel free to comment on the PR whenever you update it, unfortunately github doesn't send out notifications for force-pushes. |
87cefcd
to
8c778f2
Compare
Ok, done. |
@bors: r+ 8c778f2 Thanks! |
⌛ Testing commit 8c778f2 with merge d885154... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
2 similar comments
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-win-64-nopt-t |
@bors: retry (Please ignore the failures for now) |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
3 similar comments
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-win-32-opt |
@bors: retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-win-64-nopt-t |
@bors: retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-linux-64-x-android-t |
bors seems to be in a mood today… ;) |
Oh, no, that's just me manually cancellig (forcing) the build for the rollup. Ignore all bors comments (you're in the rollup) :) |
@bors: retry |
So sorry, thought I had added this to the rollup. |
⌛ Testing commit 8c778f2 with merge 044ee8b... |
💔 Test failed - auto-mac-64-opt |
💔 Test failed - auto-mac-32-opt |
shakes fist at stage2
|
8c778f2
to
36ba96e
Compare
Stupid me. This time I ran the complete compilation process and updated the PR. |
@bors: retry clean |
@bors: clean r+ |
⌛ Testing commit 36ba96e with merge 0021151... |
💔 Test failed - auto-win-64-nopt-t |
This looks like a temporary issue to me…can anybody trigger a retry with bors? |
@bors: retry |
⌛ Testing commit 36ba96e with merge 545b0c4... |
💔 Test failed - auto-mac-64-nopt-t |
@bors: retry |
Implements `Debug` for `RwLock` and `arc::Weak` in the same way it is implemented for `rc::Weak` (basically copy & paste). The lack of this implementation prevents the automatic implementation of `Debug` for structs containing members of these types.
Implements
Debug
forRwLock
andarc::Weak
in the same way it is implemented forrc::Weak
(basically copy & paste).The lack of this implementation prevents the automatic implementation of
Debug
for structs containing members of these types.