Point at correct span when missing comma in println

This commit is contained in:
Esteban Küber 2018-08-06 20:54:51 -07:00
parent 4862eee8b7
commit cce4ea5149
4 changed files with 24 additions and 16 deletions

View File

@ -147,7 +147,7 @@ fn parse_args(ecx: &mut ExtCtxt,
let mut named = false; let mut named = false;
while p.token != token::Eof { while p.token != token::Eof {
if !p.eat(&token::Comma) { if !p.eat(&token::Comma) {
ecx.span_err(sp, "expected token: `,`"); ecx.span_err(p.span, "expected token: `,`");
return None; return None;
} }
if p.token == token::Eof { if p.token == token::Eof {

View File

@ -7,20 +7,16 @@ LL | format!(); //~ ERROR requires at least a format string argument
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: expected token: `,` error: expected token: `,`
--> $DIR/bad-format-args.rs:13:5 --> $DIR/bad-format-args.rs:13:16
| |
LL | format!("" 1); //~ ERROR expected token: `,` LL | format!("" 1); //~ ERROR expected token: `,`
| ^^^^^^^^^^^^^^ | ^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: expected token: `,` error: expected token: `,`
--> $DIR/bad-format-args.rs:14:5 --> $DIR/bad-format-args.rs:14:19
| |
LL | format!("", 1 1); //~ ERROR expected token: `,` LL | format!("", 1 1); //~ ERROR expected token: `,`
| ^^^^^^^^^^^^^^^^^ | ^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 3 previous errors error: aborting due to 3 previous errors

View File

@ -8,7 +8,13 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
macro_rules! foo {
($a:ident, $b:ident) => ()
}
fn main() { fn main() {
println!("{}" a); println!("{}" a);
//~^ ERROR no rules expected the token `a` //~^ ERROR expected token: `,`
foo!(a b);
//~^ ERROR no rules expected the token `b`
} }

View File

@ -1,10 +1,16 @@
error: no rules expected the token `a` error: expected token: `,`
--> $DIR/missing-comma.rs:12:19 --> $DIR/missing-comma.rs:16:19
| |
LL | println!("{}" a); LL | println!("{}" a);
| ^
error: no rules expected the token `b`
--> $DIR/missing-comma.rs:18:12
|
LL | foo!(a b);
| -^ | -^
| | | |
| help: missing comma here | help: missing comma here
error: aborting due to previous error error: aborting due to 2 previous errors