std: Rename Show/String to Debug/Display

This commit is an implementation of [RFC 565][rfc] which is a stabilization of
the `std::fmt` module and the implementations of various formatting traits.
Specifically, the following changes were performed:

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md

* The `Show` trait is now deprecated, it was renamed to `Debug`
* The `String` trait is now deprecated, it was renamed to `Display`
* Many `Debug` and `Display` implementations were audited in accordance with the
  RFC and audited implementations now have the `#[stable]` attribute
  * Integers and floats no longer print a suffix
  * Smart pointers no longer print details that they are a smart pointer
  * Paths with `Debug` are now quoted and escape characters
* The `unwrap` methods on `Result` now require `Display` instead of `Debug`
* The `Error` trait no longer has a `detail` method and now requires that
  `Display` must be implemented. With the loss of `String`, this has moved into
  libcore.
* `impl<E: Error> FromError<E> for Box<Error>` now exists
* `derive(Show)` has been renamed to `derive(Debug)`. This is not currently
  warned about due to warnings being emitted on stage1+

While backwards compatibility is attempted to be maintained with a blanket
implementation of `Display` for the old `String` trait (and the same for
`Show`/`Debug`) this is still a breaking change due to primitives no longer
implementing `String` as well as modifications such as `unwrap` and the `Error`
trait. Most code is fairly straightforward to update with a rename or tweaks of
method calls.

[breaking-change]
Closes #21436
This commit is contained in:
Alex Crichton 2015-01-20 15:45:07 -08:00
parent 29bd9a06ef
commit 3cb9fa26ef
136 changed files with 763 additions and 706 deletions

View file

@ -197,7 +197,7 @@ impl<T: Writer+Send> TerminfoTerminal<T> {
let mut file = entry.unwrap();
let ti = parse(&mut file, false);
if ti.is_err() {
debug!("error parsing terminfo entry: {:?}", ti.unwrap_err());
debug!("error parsing terminfo entry: {:?}", ti.err().unwrap());
return None;
}

View file

@ -624,7 +624,7 @@ mod test {
};
let res = get_res("%p1", cap, &[p], vars);
assert!(res.is_ok(),
"Op {} failed with 1 stack entry: {}", cap, res.unwrap_err());
"Op {} failed with 1 stack entry: {}", cap, res.err().unwrap());
}
let caps = ["%+", "%-", "%*", "%/", "%m", "%&", "%|", "%A", "%O"];
for &cap in caps.iter() {
@ -636,7 +636,7 @@ mod test {
"Binop {} succeeded incorrectly with 1 stack entry", cap);
let res = get_res("%{1}%{2}", cap, &[], vars);
assert!(res.is_ok(),
"Binop {} failed with 2 stack entries: {:?}", cap, res.unwrap_err());
"Binop {} failed with 2 stack entries: {:?}", cap, res.err().unwrap());
}
}
@ -651,15 +651,15 @@ mod test {
for &(op, bs) in v.iter() {
let s = format!("%{{1}}%{{2}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[0]));
let s = format!("%{{1}}%{{1}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[1]));
let s = format!("%{{2}}%{{1}}%{}%d", op);
let res = expand(s.as_bytes(), &[], &mut Variables::new());
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(), vec!(b'0' + bs[2]));
}
}
@ -669,15 +669,15 @@ mod test {
let mut vars = Variables::new();
let s = b"\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m";
let res = expand(s, &[Number(1)], &mut vars);
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(),
"\\E[31m".bytes().collect::<Vec<_>>());
let res = expand(s, &[Number(8)], &mut vars);
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(),
"\\E[90m".bytes().collect::<Vec<_>>());
let res = expand(s, &[Number(42)], &mut vars);
assert!(res.is_ok(), res.unwrap_err());
assert!(res.is_ok(), res.err().unwrap());
assert_eq!(res.unwrap(),
"\\E[38;5;42m".bytes().collect::<Vec<_>>());
}