Suggestion for print

This commit is contained in:
csmoe 2018-06-17 10:52:02 +08:00
parent 8fa9bfeb15
commit b79a83b4e4
2 changed files with 9 additions and 2 deletions

View file

@ -14,6 +14,7 @@ use syntax::ext::build::AstBuilder;
use syntax::symbol::Symbol;
use syntax_pos;
use syntax::tokenstream;
use syntax::print::pprust;
use std::string::String;
@ -53,7 +54,13 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
}
}
_ => {
cx.span_err(e.span, "expected a literal");
let mut err = cx.struct_span_err(e.span, "expected a literal");
err.span_suggestion(
e.span,
"consider changing this to",
format!("\"{{}}\", {}", pprust::expr_to_string(&e))
);
err.emit();
}
}
}

View file

@ -2,7 +2,7 @@ error: expected a literal
--> $DIR/bad_hello.rs:12:14
|
LL | println!(3 + 4); //~ ERROR expected a literal
| ^^^^^
| ^^^^^ help: consider changing this to: `"{}", 3 + 4`
error: aborting due to previous error