The Debug implementation for Mutex looks like this:
write!(f, "Mutex {{ data: {:?} }}", &*guard)
This is bad because it does not honor the # pretty-print modifier.
println!("{:#?}", std::sync::Mutex::new(5));
It prints
instead of
A correct implementation would use debug_struct.
f.debug_struct("Mutex").field("data", &*guard).finish()
There seem to be lots of instances of this in the standard library. The following search is a good place to start.
grep -r ' {{ ' libcore libstd
The
Debugimplementation forMutexlooks like this:This is bad because it does not honor the
#pretty-print modifier.It prints
instead of
A correct implementation would use
debug_struct.There seem to be lots of instances of this in the standard library. The following search is a good place to start.