add span note

This commit is contained in:
csmoe
2018-07-04 09:01:11 +08:00
parent b79a83b4e4
commit c999b253b7

View File

@@ -55,10 +55,17 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
}
_ => {
let mut err = cx.struct_span_err(e.span, "expected a literal");
let msg = cx.codemap().span_to_snippet(e.span).unwrap_or_else(
|_| pprust::expr_to_string(&e)
);
err.span_suggestion(
e.span,
"consider changing this to",
format!("\"{{}}\", {}", pprust::expr_to_string(&e))
format!("\"{{}}\", {}", msg)
);
err.span_note(
e.span,
"you might be missing a string literal to format with",
);
err.emit();
}