From cce4ea5149e28b938d0af8466dd9af1e489f1b55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 6 Aug 2018 20:54:51 -0700 Subject: [PATCH] Point at correct span when missing comma in `println` --- src/libsyntax_ext/format.rs | 2 +- .../ui/codemap_tests/bad-format-args.stderr | 12 ++++-------- src/test/ui/macros/missing-comma.rs | 8 +++++++- src/test/ui/macros/missing-comma.stderr | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index 46c85497ee7..53f8fe2b0c2 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -147,7 +147,7 @@ fn parse_args(ecx: &mut ExtCtxt, let mut named = false; while p.token != token::Eof { if !p.eat(&token::Comma) { - ecx.span_err(sp, "expected token: `,`"); + ecx.span_err(p.span, "expected token: `,`"); return None; } if p.token == token::Eof { diff --git a/src/test/ui/codemap_tests/bad-format-args.stderr b/src/test/ui/codemap_tests/bad-format-args.stderr index d0cdeb2178f..1c801f2a790 100644 --- a/src/test/ui/codemap_tests/bad-format-args.stderr +++ b/src/test/ui/codemap_tests/bad-format-args.stderr @@ -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) error: expected token: `,` - --> $DIR/bad-format-args.rs:13:5 + --> $DIR/bad-format-args.rs:13:16 | 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: `,` - --> $DIR/bad-format-args.rs:14:5 + --> $DIR/bad-format-args.rs:14:19 | 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 diff --git a/src/test/ui/macros/missing-comma.rs b/src/test/ui/macros/missing-comma.rs index e69b1ff5a4d..ac82171a4e8 100644 --- a/src/test/ui/macros/missing-comma.rs +++ b/src/test/ui/macros/missing-comma.rs @@ -8,7 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +macro_rules! foo { + ($a:ident, $b:ident) => () +} + fn main() { println!("{}" a); - //~^ ERROR no rules expected the token `a` + //~^ ERROR expected token: `,` + foo!(a b); + //~^ ERROR no rules expected the token `b` } diff --git a/src/test/ui/macros/missing-comma.stderr b/src/test/ui/macros/missing-comma.stderr index cc12e43fc27..3467032d9b5 100644 --- a/src/test/ui/macros/missing-comma.stderr +++ b/src/test/ui/macros/missing-comma.stderr @@ -1,10 +1,16 @@ -error: no rules expected the token `a` - --> $DIR/missing-comma.rs:12:19 +error: expected token: `,` + --> $DIR/missing-comma.rs:16:19 | LL | println!("{}" a); - | -^ - | | - | help: missing comma here + | ^ -error: aborting due to previous error +error: no rules expected the token `b` + --> $DIR/missing-comma.rs:18:12 + | +LL | foo!(a b); + | -^ + | | + | help: missing comma here + +error: aborting due to 2 previous errors