Skip to content

Commit e5a5ca4

Browse files
committed
use field_with to print "<locked>" and "<uninit>" in Debug
1 parent 41f2b6b commit e5a5ca4

File tree

7 files changed

+7
-6
lines changed

7 files changed

+7
-6
lines changed

library/core/src/cell/lazy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
364364
let mut d = f.debug_tuple("LazyCell");
365365
match LazyCell::get(self) {
366366
Some(data) => d.field(data),
367-
None => d.field(&format_args!("<uninit>")),
367+
None => d.field_with(|f| f.write_str("<uninit>")),
368368
};
369369
d.finish()
370370
}

library/core/src/cell/once.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceCell<T> {
362362
let mut d = f.debug_tuple("OnceCell");
363363
match self.get() {
364364
Some(v) => d.field(v),
365-
None => d.field(&format_args!("<uninit>")),
365+
None => d.field_with(|f| f.write_str("<uninit>")),
366366
};
367367
d.finish()
368368
}

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
#![feature(const_try)]
340340
#![feature(core_intrinsics)]
341341
#![feature(core_io_borrowed_buf)]
342+
#![feature(debug_closure_helpers)]
342343
#![feature(drop_guard)]
343344
#![feature(duration_constants)]
344345
#![feature(error_generic_member_access)]

library/std/src/sync/lazy_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyLock<T, F> {
395395
let mut d = f.debug_tuple("LazyLock");
396396
match LazyLock::get(self) {
397397
Some(v) => d.field(v),
398-
None => d.field(&format_args!("<uninit>")),
398+
None => d.field_with(|f| f.write_str("<uninit>")),
399399
};
400400
d.finish()
401401
}

library/std/src/sync/once_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<T: fmt::Debug> fmt::Debug for OnceLock<T> {
600600
let mut d = f.debug_tuple("OnceLock");
601601
match self.get() {
602602
Some(v) => d.field(v),
603-
None => d.field(&format_args!("<uninit>")),
603+
None => d.field_with(|f| f.write_str("<uninit>")),
604604
};
605605
d.finish()
606606
}

library/std/src/sync/poison/rwlock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for RwLock<T> {
684684
d.field("data", &&**err.get_ref());
685685
}
686686
Err(TryLockError::WouldBlock) => {
687-
d.field("data", &format_args!("<locked>"));
687+
d.field_with("data", |f| f.write_str("<locked>"));
688688
}
689689
}
690690
d.field("poisoned", &self.poison.get());

library/std/src/sync/reentrant_lock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<T: fmt::Debug + ?Sized> fmt::Debug for ReentrantLock<T> {
373373
let mut d = f.debug_struct("ReentrantLock");
374374
match self.try_lock() {
375375
Some(v) => d.field("data", &&*v),
376-
None => d.field("data", &format_args!("<locked>")),
376+
None => d.field_with("data", |f| f.write_str("<locked>")),
377377
};
378378
d.finish_non_exhaustive()
379379
}

0 commit comments

Comments
 (0)