Skip to content

Commit

Permalink
Point to macro def span instead of whole body
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 24, 2018
1 parent 8227a93 commit 1ab45ec
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 179 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_rules.rs
Expand Up @@ -187,7 +187,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
err.span_label(span, best_fail_msg);
if let Some(sp) = def_span {
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
err.span_label(sp, "when calling this macro");
err.span_label(cx.source_map().def_span(sp), "when calling this macro");
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/test/ui/empty/empty-comment.stderr
@@ -1,13 +1,11 @@
error: unexpected end of macro invocation
--> $DIR/empty-comment.rs:20:5
|
LL | / macro_rules! one_arg_macro {
LL | | ($fmt:expr) => (print!(concat!($fmt, "/n")));
LL | | }
| |_- when calling this macro
LL | macro_rules! one_arg_macro {
| -------------------------- when calling this macro
...
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation

error: aborting due to previous error

10 changes: 4 additions & 6 deletions src/test/ui/issues/issue-7970a.stderr
@@ -1,13 +1,11 @@
error: unexpected end of macro invocation
--> $DIR/issue-7970a.rs:16:5
|
LL | / macro_rules! one_arg_macro {
LL | | ($fmt:expr) => (print!(concat!($fmt, "/n")));
LL | | }
| |_- when calling this macro
LL | macro_rules! one_arg_macro {
| -------------------------- when calling this macro
...
LL | one_arg_macro!();
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
LL | one_arg_macro!();
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation

error: aborting due to previous error

36 changes: 12 additions & 24 deletions src/test/ui/macros/macro-at-most-once-rep-2018-feature-gate.stderr
Expand Up @@ -51,41 +51,29 @@ LL | ($(a)?*) => {}
error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:41:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | //~^ERROR using the `?` macro Kleene operator for
LL | | //~|ERROR expected `*` or `+`
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:42:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | //~^ERROR using the `?` macro Kleene operator for
LL | | //~|ERROR expected `*` or `+`
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:43:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | //~^ERROR using the `?` macro Kleene operator for
LL | | //~|ERROR expected `*` or `+`
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: aborting due to 10 previous errors

Expand Down
110 changes: 44 additions & 66 deletions src/test/ui/macros/macro-at-most-once-rep-2018.stderr
Expand Up @@ -7,123 +7,101 @@ LL | ($(a),?) => {} //~ERROR the `?` macro repetition operator
error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:36:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:37:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:38:11
|
LL | / macro_rules! foo {
LL | | ($(a)?) => {}
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2018.rs:40:5
|
LL | / macro_rules! barplus {
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
LL | | }
| |_- when calling this macro
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(); //~ERROR unexpected end of macro invocation
| ^^^^^^^^^^^ unexpected end of macro invocation
LL | barplus!(); //~ERROR unexpected end of macro invocation
| ^^^^^^^^^^^ unexpected end of macro invocation

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2018.rs:41:14
|
LL | / macro_rules! barplus {
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
LL | | }
| |_- when calling this macro
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a); //~ERROR unexpected end of macro invocation
| ^ unexpected end of macro invocation
LL | barplus!(a); //~ERROR unexpected end of macro invocation
| ^ unexpected end of macro invocation

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:42:15
|
LL | / macro_rules! barplus {
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
LL | | }
| |_- when calling this macro
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:43:15
|
LL | / macro_rules! barplus {
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
LL | | }
| |_- when calling this macro
LL | macro_rules! barplus {
| -------------------- when calling this macro
...
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2018.rs:47:5
|
LL | / macro_rules! barstar {
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
LL | | }
| |_- when calling this macro
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(); //~ERROR unexpected end of macro invocation
| ^^^^^^^^^^^ unexpected end of macro invocation
LL | barstar!(); //~ERROR unexpected end of macro invocation
| ^^^^^^^^^^^ unexpected end of macro invocation

error: unexpected end of macro invocation
--> $DIR/macro-at-most-once-rep-2018.rs:48:14
|
LL | / macro_rules! barstar {
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
LL | | }
| |_- when calling this macro
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a); //~ERROR unexpected end of macro invocation
| ^ unexpected end of macro invocation
LL | barstar!(a); //~ERROR unexpected end of macro invocation
| ^ unexpected end of macro invocation

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:49:15
|
LL | / macro_rules! barstar {
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
LL | | }
| |_- when calling this macro
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: no rules expected the token `?`
--> $DIR/macro-at-most-once-rep-2018.rs:50:15
|
LL | / macro_rules! barstar {
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
LL | | }
| |_- when calling this macro
LL | macro_rules! barstar {
| -------------------- when calling this macro
...
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
| ^ no rules expected the token `?`

error: aborting due to 12 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/macros/macro-non-lifetime.stderr
Expand Up @@ -2,7 +2,7 @@ error: no rules expected the token `a`
--> $DIR/macro-non-lifetime.rs:18:8
|
LL | macro_rules! m { ($x:lifetime) => { } }
| --------------------------------------- when calling this macro
| -------------- when calling this macro
...
LL | m!(a);
| ^ no rules expected the token `a`
Expand Down
68 changes: 22 additions & 46 deletions src/test/ui/macros/missing-comma.stderr
Expand Up @@ -7,68 +7,44 @@ LL | println!("{}" a);
error: no rules expected the token `b`
--> $DIR/missing-comma.rs:22:12
|
LL | / macro_rules! foo {
LL | | ($a:ident) => ();
LL | | ($a:ident, $b:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a b);
| -^ no rules expected the token `b`
| |
| help: missing comma here
LL | foo!(a b);
| -^ no rules expected the token `b`
| |
| help: missing comma here

error: no rules expected the token `e`
--> $DIR/missing-comma.rs:24:21
|
LL | / macro_rules! foo {
LL | | ($a:ident) => ();
LL | | ($a:ident, $b:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a, b, c, d e);
| -^ no rules expected the token `e`
| |
| help: missing comma here
LL | foo!(a, b, c, d e);
| -^ no rules expected the token `e`
| |
| help: missing comma here

error: no rules expected the token `d`
--> $DIR/missing-comma.rs:26:18
|
LL | / macro_rules! foo {
LL | | ($a:ident) => ();
LL | | ($a:ident, $b:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a, b, c d, e);
| -^ no rules expected the token `d`
| |
| help: missing comma here
LL | foo!(a, b, c d, e);
| -^ no rules expected the token `d`
| |
| help: missing comma here

error: no rules expected the token `d`
--> $DIR/missing-comma.rs:28:18
|
LL | / macro_rules! foo {
LL | | ($a:ident) => ();
LL | | ($a:ident, $b:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
LL | | }
| |_- when calling this macro
LL | macro_rules! foo {
| ---------------- when calling this macro
...
LL | foo!(a, b, c d e);
| ^ no rules expected the token `d`
LL | foo!(a, b, c d e);
| ^ no rules expected the token `d`

error: aborting due to 5 previous errors

16 changes: 7 additions & 9 deletions src/test/ui/macros/trace_faulty_macros.stderr
@@ -1,16 +1,14 @@
error: no rules expected the token `bcd`
--> $DIR/trace_faulty_macros.rs:17:26
|
LL | / macro_rules! my_faulty_macro {
LL | | () => {
LL | | my_faulty_macro!(bcd); //~ ERROR no rules
| | ^^^ no rules expected the token `bcd`
LL | | };
LL | | }
| |_- when calling this macro
LL | macro_rules! my_faulty_macro {
| ---------------------------- when calling this macro
LL | () => {
LL | my_faulty_macro!(bcd); //~ ERROR no rules
| ^^^ no rules expected the token `bcd`
...
LL | my_faulty_macro!();
| ------------------- in this macro invocation
LL | my_faulty_macro!();
| ------------------- in this macro invocation

note: trace_macro
--> $DIR/trace_faulty_macros.rs:43:5
Expand Down

0 comments on commit 1ab45ec

Please sign in to comment.