diff options
| author | Sean McArthur <sean.monstar@gmail.com> | 2014-12-20 00:09:35 -0800 |
|---|---|---|
| committer | Sean McArthur <sean.monstar@gmail.com> | 2015-01-06 14:49:42 -0800 |
| commit | 44440e5c18a1dbcc9685866ffffe00c508929079 (patch) | |
| tree | b66c50cd1e471dc0e37b8a0db2cf7f8f28fbac5f /src/libsyntax/ext | |
| parent | 8efd9901b628d687d11a4d0ccc153553b38ada49 (diff) | |
| download | rust-44440e5c18a1dbcc9685866ffffe00c508929079.tar.gz rust-44440e5c18a1dbcc9685866ffffe00c508929079.zip | |
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]
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/deriving/show.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/format.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/mtwt.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/transcribe.rs | 4 |
6 files changed, 11 insertions, 11 deletions
diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index eceac4e9a83..67df6773efe 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -90,7 +90,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, for (i, field) in fields.iter().enumerate() { if i != 0 { format_string.push_str(", "); } - format_string.push_str("{}"); + format_string.push_str("{:?}"); exprs.push(field.self_.clone()); } @@ -107,7 +107,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, let name = token::get_ident(field.name.unwrap()); format_string.push_str(" "); format_string.push_str(name.get()); - format_string.push_str(": {}"); + format_string.push_str(": {:?}"); exprs.push(field.self_.clone()); } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 212ec3b0903..2360cbc2874 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -36,7 +36,7 @@ pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander, impl_ty: Option<P<ast::Ty>>) -> P<ast::Ty> { - debug!("expanding type {} with impl_ty {}", t, impl_ty); + debug!("expanding type {:?} with impl_ty {:?}", t, impl_ty); let t = match (t.node.clone(), impl_ty) { // Expand uses of `Self` in impls to the concrete type. (ast::Ty_::TyPath(ref path, _), Some(ref impl_ty)) => { diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 1f39555f496..4638500ebf4 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -607,7 +607,7 @@ impl<'a, 'b> Context<'a, 'b> { let trait_ = match *ty { Known(ref tyname) => { match tyname[] { - "" => "Show", + "" => "String", "?" => "Show", "e" => "LowerExp", "E" => "UpperExp", diff --git a/src/libsyntax/ext/mtwt.rs b/src/libsyntax/ext/mtwt.rs index 4075b208f78..5173541e350 100644 --- a/src/libsyntax/ext/mtwt.rs +++ b/src/libsyntax/ext/mtwt.rs @@ -121,7 +121,7 @@ fn new_sctable_internal() -> SCTable { pub fn display_sctable(table: &SCTable) { error!("SC table:"); for (idx,val) in table.table.borrow().iter().enumerate() { - error!("{:4} : {}",idx,val); + error!("{:4} : {:?}",idx,val); } } diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index a49df457cb3..7d9fc5958aa 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -135,7 +135,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let bytes = match File::open(&file).read_to_end() { Err(e) => { cx.span_err(sp, - format!("couldn't read {}: {}", + format!("couldn't read {:?}: {}", file.display(), e)[]); return DummyResult::expr(sp); @@ -146,7 +146,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Ok(src) => { // Add this input file to the code map to make it available as // dependency information - let filename = file.display().to_string(); + let filename = format!("{:?}", file.display()); let interned = token::intern_and_get_ident(src[]); cx.codemap().new_filemap(filename, src); @@ -154,7 +154,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } Err(_) => { cx.span_err(sp, - format!("{} wasn't a utf-8 file", + format!("{:?} wasn't a utf-8 file", file.display())[]); return DummyResult::expr(sp); } @@ -177,7 +177,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) match File::open(&file).read_to_end() { Err(e) => { cx.span_err(sp, - format!("couldn't read {}: {}", file.display(), e)[]); + format!("couldn't read {:?}: {}", file.display(), e)[]); return DummyResult::expr(sp); } Ok(bytes) => { diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index e4e6f5ac6b0..bc57ee0eb6f 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -128,7 +128,7 @@ impl Add for LockstepIterSize { let l_n = token::get_ident(l_id.clone()); let r_n = token::get_ident(r_id); LisContradiction(format!("inconsistent lockstep iteration: \ - '{}' has {} items, but '{}' has {}", + '{:?}' has {} items, but '{:?}' has {}", l_n, l_len, r_n, r_len).to_string()) } }, @@ -296,7 +296,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { MatchedSeq(..) => { r.sp_diag.span_fatal( r.cur_span, /* blame the macro writer */ - format!("variable '{}' is still repeating at this depth", + format!("variable '{:?}' is still repeating at this depth", token::get_ident(ident))[]); } } |
