Skip to content

Commit 1ab45ec

Browse files
committed
Point to macro def span instead of whole body
1 parent 8227a93 commit 1ab45ec

11 files changed

+107
-179
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
187187
err.span_label(span, best_fail_msg);
188188
if let Some(sp) = def_span {
189189
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
190-
err.span_label(sp, "when calling this macro");
190+
err.span_label(cx.source_map().def_span(sp), "when calling this macro");
191191
}
192192
}
193193

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
error: unexpected end of macro invocation
22
--> $DIR/empty-comment.rs:20:5
33
|
4-
LL | / macro_rules! one_arg_macro {
5-
LL | | ($fmt:expr) => (print!(concat!($fmt, "/n")));
6-
LL | | }
7-
| |_- when calling this macro
4+
LL | macro_rules! one_arg_macro {
5+
| -------------------------- when calling this macro
86
...
9-
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
10-
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
7+
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
8+
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
119

1210
error: aborting due to previous error
1311

src/test/ui/issues/issue-7970a.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
error: unexpected end of macro invocation
22
--> $DIR/issue-7970a.rs:16:5
33
|
4-
LL | / macro_rules! one_arg_macro {
5-
LL | | ($fmt:expr) => (print!(concat!($fmt, "/n")));
6-
LL | | }
7-
| |_- when calling this macro
4+
LL | macro_rules! one_arg_macro {
5+
| -------------------------- when calling this macro
86
...
9-
LL | one_arg_macro!();
10-
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
7+
LL | one_arg_macro!();
8+
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
119

1210
error: aborting due to previous error
1311

src/test/ui/macros/macro-at-most-once-rep-2018-feature-gate.stderr

+12-24
Original file line numberDiff line numberDiff line change
@@ -51,41 +51,29 @@ LL | ($(a)?*) => {}
5151
error: no rules expected the token `?`
5252
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:41:11
5353
|
54-
LL | / macro_rules! foo {
55-
LL | | ($(a)?) => {}
56-
LL | | //~^ERROR using the `?` macro Kleene operator for
57-
LL | | //~|ERROR expected `*` or `+`
58-
LL | | }
59-
| |_- when calling this macro
54+
LL | macro_rules! foo {
55+
| ---------------- when calling this macro
6056
...
61-
LL | foo!(a?); //~ ERROR no rules expected the token `?`
62-
| ^ no rules expected the token `?`
57+
LL | foo!(a?); //~ ERROR no rules expected the token `?`
58+
| ^ no rules expected the token `?`
6359

6460
error: no rules expected the token `?`
6561
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:42:11
6662
|
67-
LL | / macro_rules! foo {
68-
LL | | ($(a)?) => {}
69-
LL | | //~^ERROR using the `?` macro Kleene operator for
70-
LL | | //~|ERROR expected `*` or `+`
71-
LL | | }
72-
| |_- when calling this macro
63+
LL | macro_rules! foo {
64+
| ---------------- when calling this macro
7365
...
74-
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
75-
| ^ no rules expected the token `?`
66+
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
67+
| ^ no rules expected the token `?`
7668

7769
error: no rules expected the token `?`
7870
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:43:11
7971
|
80-
LL | / macro_rules! foo {
81-
LL | | ($(a)?) => {}
82-
LL | | //~^ERROR using the `?` macro Kleene operator for
83-
LL | | //~|ERROR expected `*` or `+`
84-
LL | | }
85-
| |_- when calling this macro
72+
LL | macro_rules! foo {
73+
| ---------------- when calling this macro
8674
...
87-
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
88-
| ^ no rules expected the token `?`
75+
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
76+
| ^ no rules expected the token `?`
8977

9078
error: aborting due to 10 previous errors
9179

src/test/ui/macros/macro-at-most-once-rep-2018.stderr

+44-66
Original file line numberDiff line numberDiff line change
@@ -7,123 +7,101 @@ LL | ($(a),?) => {} //~ERROR the `?` macro repetition operator
77
error: no rules expected the token `?`
88
--> $DIR/macro-at-most-once-rep-2018.rs:36:11
99
|
10-
LL | / macro_rules! foo {
11-
LL | | ($(a)?) => {}
12-
LL | | }
13-
| |_- when calling this macro
10+
LL | macro_rules! foo {
11+
| ---------------- when calling this macro
1412
...
15-
LL | foo!(a?); //~ ERROR no rules expected the token `?`
16-
| ^ no rules expected the token `?`
13+
LL | foo!(a?); //~ ERROR no rules expected the token `?`
14+
| ^ no rules expected the token `?`
1715

1816
error: no rules expected the token `?`
1917
--> $DIR/macro-at-most-once-rep-2018.rs:37:11
2018
|
21-
LL | / macro_rules! foo {
22-
LL | | ($(a)?) => {}
23-
LL | | }
24-
| |_- when calling this macro
19+
LL | macro_rules! foo {
20+
| ---------------- when calling this macro
2521
...
26-
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
27-
| ^ no rules expected the token `?`
22+
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
23+
| ^ no rules expected the token `?`
2824

2925
error: no rules expected the token `?`
3026
--> $DIR/macro-at-most-once-rep-2018.rs:38:11
3127
|
32-
LL | / macro_rules! foo {
33-
LL | | ($(a)?) => {}
34-
LL | | }
35-
| |_- when calling this macro
28+
LL | macro_rules! foo {
29+
| ---------------- when calling this macro
3630
...
37-
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
38-
| ^ no rules expected the token `?`
31+
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
32+
| ^ no rules expected the token `?`
3933

4034
error: unexpected end of macro invocation
4135
--> $DIR/macro-at-most-once-rep-2018.rs:40:5
4236
|
43-
LL | / macro_rules! barplus {
44-
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
45-
LL | | }
46-
| |_- when calling this macro
37+
LL | macro_rules! barplus {
38+
| -------------------- when calling this macro
4739
...
48-
LL | barplus!(); //~ERROR unexpected end of macro invocation
49-
| ^^^^^^^^^^^ unexpected end of macro invocation
40+
LL | barplus!(); //~ERROR unexpected end of macro invocation
41+
| ^^^^^^^^^^^ unexpected end of macro invocation
5042

5143
error: unexpected end of macro invocation
5244
--> $DIR/macro-at-most-once-rep-2018.rs:41:14
5345
|
54-
LL | / macro_rules! barplus {
55-
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
56-
LL | | }
57-
| |_- when calling this macro
46+
LL | macro_rules! barplus {
47+
| -------------------- when calling this macro
5848
...
59-
LL | barplus!(a); //~ERROR unexpected end of macro invocation
60-
| ^ unexpected end of macro invocation
49+
LL | barplus!(a); //~ERROR unexpected end of macro invocation
50+
| ^ unexpected end of macro invocation
6151

6252
error: no rules expected the token `?`
6353
--> $DIR/macro-at-most-once-rep-2018.rs:42:15
6454
|
65-
LL | / macro_rules! barplus {
66-
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
67-
LL | | }
68-
| |_- when calling this macro
55+
LL | macro_rules! barplus {
56+
| -------------------- when calling this macro
6957
...
70-
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
71-
| ^ no rules expected the token `?`
58+
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
59+
| ^ no rules expected the token `?`
7260

7361
error: no rules expected the token `?`
7462
--> $DIR/macro-at-most-once-rep-2018.rs:43:15
7563
|
76-
LL | / macro_rules! barplus {
77-
LL | | ($(a)?+) => {} // ok. matches "a+" and "+"
78-
LL | | }
79-
| |_- when calling this macro
64+
LL | macro_rules! barplus {
65+
| -------------------- when calling this macro
8066
...
81-
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
82-
| ^ no rules expected the token `?`
67+
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
68+
| ^ no rules expected the token `?`
8369

8470
error: unexpected end of macro invocation
8571
--> $DIR/macro-at-most-once-rep-2018.rs:47:5
8672
|
87-
LL | / macro_rules! barstar {
88-
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
89-
LL | | }
90-
| |_- when calling this macro
73+
LL | macro_rules! barstar {
74+
| -------------------- when calling this macro
9175
...
92-
LL | barstar!(); //~ERROR unexpected end of macro invocation
93-
| ^^^^^^^^^^^ unexpected end of macro invocation
76+
LL | barstar!(); //~ERROR unexpected end of macro invocation
77+
| ^^^^^^^^^^^ unexpected end of macro invocation
9478

9579
error: unexpected end of macro invocation
9680
--> $DIR/macro-at-most-once-rep-2018.rs:48:14
9781
|
98-
LL | / macro_rules! barstar {
99-
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
100-
LL | | }
101-
| |_- when calling this macro
82+
LL | macro_rules! barstar {
83+
| -------------------- when calling this macro
10284
...
103-
LL | barstar!(a); //~ERROR unexpected end of macro invocation
104-
| ^ unexpected end of macro invocation
85+
LL | barstar!(a); //~ERROR unexpected end of macro invocation
86+
| ^ unexpected end of macro invocation
10587

10688
error: no rules expected the token `?`
10789
--> $DIR/macro-at-most-once-rep-2018.rs:49:15
10890
|
109-
LL | / macro_rules! barstar {
110-
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
111-
LL | | }
112-
| |_- when calling this macro
91+
LL | macro_rules! barstar {
92+
| -------------------- when calling this macro
11393
...
114-
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
115-
| ^ no rules expected the token `?`
94+
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
95+
| ^ no rules expected the token `?`
11696

11797
error: no rules expected the token `?`
11898
--> $DIR/macro-at-most-once-rep-2018.rs:50:15
11999
|
120-
LL | / macro_rules! barstar {
121-
LL | | ($(a)?*) => {} // ok. matches "a*" and "*"
122-
LL | | }
123-
| |_- when calling this macro
100+
LL | macro_rules! barstar {
101+
| -------------------- when calling this macro
124102
...
125-
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
126-
| ^ no rules expected the token `?`
103+
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
104+
| ^ no rules expected the token `?`
127105

128106
error: aborting due to 12 previous errors
129107

src/test/ui/macros/macro-non-lifetime.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: no rules expected the token `a`
22
--> $DIR/macro-non-lifetime.rs:18:8
33
|
44
LL | macro_rules! m { ($x:lifetime) => { } }
5-
| --------------------------------------- when calling this macro
5+
| -------------- when calling this macro
66
...
77
LL | m!(a);
88
| ^ no rules expected the token `a`

src/test/ui/macros/missing-comma.stderr

+22-46
Original file line numberDiff line numberDiff line change
@@ -7,68 +7,44 @@ LL | println!("{}" a);
77
error: no rules expected the token `b`
88
--> $DIR/missing-comma.rs:22:12
99
|
10-
LL | / macro_rules! foo {
11-
LL | | ($a:ident) => ();
12-
LL | | ($a:ident, $b:ident) => ();
13-
LL | | ($a:ident, $b:ident, $c:ident) => ();
14-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
15-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
16-
LL | | }
17-
| |_- when calling this macro
10+
LL | macro_rules! foo {
11+
| ---------------- when calling this macro
1812
...
19-
LL | foo!(a b);
20-
| -^ no rules expected the token `b`
21-
| |
22-
| help: missing comma here
13+
LL | foo!(a b);
14+
| -^ no rules expected the token `b`
15+
| |
16+
| help: missing comma here
2317

2418
error: no rules expected the token `e`
2519
--> $DIR/missing-comma.rs:24:21
2620
|
27-
LL | / macro_rules! foo {
28-
LL | | ($a:ident) => ();
29-
LL | | ($a:ident, $b:ident) => ();
30-
LL | | ($a:ident, $b:ident, $c:ident) => ();
31-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
32-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
33-
LL | | }
34-
| |_- when calling this macro
21+
LL | macro_rules! foo {
22+
| ---------------- when calling this macro
3523
...
36-
LL | foo!(a, b, c, d e);
37-
| -^ no rules expected the token `e`
38-
| |
39-
| help: missing comma here
24+
LL | foo!(a, b, c, d e);
25+
| -^ no rules expected the token `e`
26+
| |
27+
| help: missing comma here
4028

4129
error: no rules expected the token `d`
4230
--> $DIR/missing-comma.rs:26:18
4331
|
44-
LL | / macro_rules! foo {
45-
LL | | ($a:ident) => ();
46-
LL | | ($a:ident, $b:ident) => ();
47-
LL | | ($a:ident, $b:ident, $c:ident) => ();
48-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
49-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
50-
LL | | }
51-
| |_- when calling this macro
32+
LL | macro_rules! foo {
33+
| ---------------- when calling this macro
5234
...
53-
LL | foo!(a, b, c d, e);
54-
| -^ no rules expected the token `d`
55-
| |
56-
| help: missing comma here
35+
LL | foo!(a, b, c d, e);
36+
| -^ no rules expected the token `d`
37+
| |
38+
| help: missing comma here
5739

5840
error: no rules expected the token `d`
5941
--> $DIR/missing-comma.rs:28:18
6042
|
61-
LL | / macro_rules! foo {
62-
LL | | ($a:ident) => ();
63-
LL | | ($a:ident, $b:ident) => ();
64-
LL | | ($a:ident, $b:ident, $c:ident) => ();
65-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
66-
LL | | ($a:ident, $b:ident, $c:ident, $d:ident, $e:ident) => ();
67-
LL | | }
68-
| |_- when calling this macro
43+
LL | macro_rules! foo {
44+
| ---------------- when calling this macro
6945
...
70-
LL | foo!(a, b, c d e);
71-
| ^ no rules expected the token `d`
46+
LL | foo!(a, b, c d e);
47+
| ^ no rules expected the token `d`
7248

7349
error: aborting due to 5 previous errors
7450

src/test/ui/macros/trace_faulty_macros.stderr

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
error: no rules expected the token `bcd`
22
--> $DIR/trace_faulty_macros.rs:17:26
33
|
4-
LL | / macro_rules! my_faulty_macro {
5-
LL | | () => {
6-
LL | | my_faulty_macro!(bcd); //~ ERROR no rules
7-
| | ^^^ no rules expected the token `bcd`
8-
LL | | };
9-
LL | | }
10-
| |_- when calling this macro
4+
LL | macro_rules! my_faulty_macro {
5+
| ---------------------------- when calling this macro
6+
LL | () => {
7+
LL | my_faulty_macro!(bcd); //~ ERROR no rules
8+
| ^^^ no rules expected the token `bcd`
119
...
12-
LL | my_faulty_macro!();
13-
| ------------------- in this macro invocation
10+
LL | my_faulty_macro!();
11+
| ------------------- in this macro invocation
1412

1513
note: trace_macro
1614
--> $DIR/trace_faulty_macros.rs:43:5

0 commit comments

Comments
 (0)