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
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)) => {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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))[]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue