core: split into fmt::Show and fmt::String
fmt::Show is for debugging, and can and should be implemented for all public types. This trait is used with `{:?}` syntax. There still exists #[derive(Show)]. fmt::String is for types that faithfully be represented as a String. Because of this, there is no way to derive fmt::String, all implementations must be purposeful. It is used by the default format syntax, `{}`. This will break most instances of `{}`, since that now requires the type to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the correct fix. Types that were being printed specifically for users should receive a fmt::String implementation to fix this. Part of #20013 [breaking-change]
This commit is contained in:
parent
8efd9901b6
commit
44440e5c18
252 changed files with 1996 additions and 1366 deletions
|
@ -581,7 +581,7 @@ impl<T: Eq> Eq for Arc<T> {}
|
|||
|
||||
impl<T: fmt::Show> fmt::Show for Arc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
(**self).fmt(f)
|
||||
write!(f, "Arc({:?})", (**self))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -794,7 +794,7 @@ mod tests {
|
|||
#[test]
|
||||
fn show_arc() {
|
||||
let a = Arc::new(5u32);
|
||||
assert!(format!("{}", a) == "5")
|
||||
assert!(format!("{:?}", a) == "Arc(5u32)")
|
||||
}
|
||||
|
||||
// Make sure deriving works with Arc<T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue