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:
Sean McArthur 2014-12-20 00:09:35 -08:00
parent 8efd9901b6
commit 44440e5c18
252 changed files with 1996 additions and 1366 deletions

View file

@ -488,7 +488,7 @@ impl<'a> Parser<'a> {
/// followed by some token from the set edible + inedible. Recover
/// from anticipated input errors, discarding erroneous characters.
pub fn commit_expr(&mut self, e: &Expr, edible: &[token::Token], inedible: &[token::Token]) {
debug!("commit_expr {}", e);
debug!("commit_expr {:?}", e);
if let ExprPath(..) = e.node {
// might be unit-struct construction; check for recoverableinput error.
let mut expected = edible.iter().map(|x| x.clone()).collect::<Vec<_>>();
@ -5113,7 +5113,7 @@ impl<'a> Parser<'a> {
attrs = tmp;
first = false;
}
debug!("parse_mod_items: parse_item_or_view_item(attrs={})",
debug!("parse_mod_items: parse_item_or_view_item(attrs={:?})",
attrs);
match self.parse_item_or_view_item(attrs,
true /* macros allowed */) {
@ -5250,7 +5250,7 @@ impl<'a> Parser<'a> {
format!("file not found for module `{}`",
mod_name)[],
format!("name the file either {} or {} inside \
the directory {}",
the directory {:?}",
default_path_str,
secondary_path_str,
dir_path.display())[]);