Skip to content

Commit b79a83b

Browse files
committed
Suggestion for print
1 parent 8fa9bfe commit b79a83b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/libsyntax_ext/concat.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use syntax::ext::build::AstBuilder;
1414
use syntax::symbol::Symbol;
1515
use syntax_pos;
1616
use syntax::tokenstream;
17+
use syntax::print::pprust;
1718

1819
use std::string::String;
1920

@@ -53,7 +54,13 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
5354
}
5455
}
5556
_ => {
56-
cx.span_err(e.span, "expected a literal");
57+
let mut err = cx.struct_span_err(e.span, "expected a literal");
58+
err.span_suggestion(
59+
e.span,
60+
"consider changing this to",
61+
format!("\"{{}}\", {}", pprust::expr_to_string(&e))
62+
);
63+
err.emit();
5764
}
5865
}
5966
}

src/test/ui/macros/bad_hello.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: expected a literal
22
--> $DIR/bad_hello.rs:12:14
33
|
44
LL | println!(3 + 4); //~ ERROR expected a literal
5-
| ^^^^^
5+
| ^^^^^ help: consider changing this to: `"{}", 3 + 4`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)