Skip to content

Commit 8bb7dba

Browse files
committed
Dont abort on first macro error
1 parent 878013c commit 8bb7dba

File tree

5 files changed

+139
-1
lines changed

5 files changed

+139
-1
lines changed

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
172172
}
173173

174174
let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
175-
cx.span_fatal(best_fail_spot.substitute_dummy(sp), &best_fail_msg);
175+
cx.span_err(best_fail_spot.substitute_dummy(sp), &best_fail_msg);
176+
cx.trace_macros_diag();
177+
DummyResult::any(sp)
176178
}
177179

178180
// Note that macro-by-example's input is also matched against a token tree:

src/test/ui/macros/assert_eq_trailing_comma.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ error: unexpected end of macro invocation
44
12 | assert_eq!(1, 1,);
55
| ^
66

7+
error: aborting due to previous error
8+

src/test/ui/macros/assert_ne_trailing_comma.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ error: unexpected end of macro invocation
44
12 | assert_ne!(1, 2,);
55
| ^
66

7+
error: aborting due to previous error
8+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z trace-macros
12+
13+
#![recursion_limit="4"]
14+
15+
macro_rules! my_faulty_macro {
16+
() => {
17+
my_faulty_macro!(bcd);
18+
};
19+
}
20+
21+
macro_rules! nested_pat_macro {
22+
() => {
23+
nested_pat_macro!(inner);
24+
};
25+
(inner) => {
26+
a | b | 1 ... 3 | _
27+
}
28+
}
29+
30+
macro_rules! my_recursive_macro {
31+
() => {
32+
my_recursive_macro!();
33+
};
34+
}
35+
36+
macro_rules! my_macro {
37+
() => {
38+
39+
};
40+
}
41+
42+
fn main() {
43+
my_faulty_macro!();
44+
nested_pat_macro!();
45+
my_recursive_macro!();
46+
test!();
47+
non_exisiting!();
48+
derive!(Debug);
49+
}
50+
51+
#[my_macro]
52+
fn use_bang_macro_as_attr(){}
53+
54+
#[derive(Debug)]
55+
fn use_derive_macro_as_attr(){}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
error: no rules expected the token `bcd`
2+
--> $DIR/trace_faulty_macros.rs:17:26
3+
|
4+
17 | my_faulty_macro!(bcd);
5+
| ^^^
6+
...
7+
43 | my_faulty_macro!();
8+
| ------------------- in this macro invocation
9+
10+
note: trace_macro
11+
--> $DIR/trace_faulty_macros.rs:43:5
12+
|
13+
43 | my_faulty_macro!();
14+
| ^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: expanding `my_faulty_macro! { }`
17+
= note: to `my_faulty_macro ! ( bcd ) ;`
18+
= note: expanding `my_faulty_macro! { bcd }`
19+
20+
error: expected expression, found `_`
21+
--> $DIR/trace_faulty_macros.rs:26:27
22+
|
23+
26 | a | b | 1 ... 3 | _
24+
| ^
25+
...
26+
44 | nested_pat_macro!();
27+
| -------------------- in this macro invocation
28+
29+
error: recursion limit reached while expanding the macro `my_recursive_macro`
30+
--> $DIR/trace_faulty_macros.rs:32:9
31+
|
32+
32 | my_recursive_macro!();
33+
| ^^^^^^^^^^^^^^^^^^^^^^
34+
...
35+
45 | my_recursive_macro!();
36+
| ---------------------- in this macro invocation
37+
|
38+
= help: consider adding a `#![recursion_limit="8"]` attribute to your crate
39+
40+
note: trace_macro
41+
--> $DIR/trace_faulty_macros.rs:45:5
42+
|
43+
45 | my_recursive_macro!();
44+
| ^^^^^^^^^^^^^^^^^^^^^^
45+
|
46+
= note: expanding `my_recursive_macro! { }`
47+
= note: to `my_recursive_macro ! ( ) ;`
48+
= note: expanding `my_recursive_macro! { }`
49+
= note: to `my_recursive_macro ! ( ) ;`
50+
= note: expanding `my_recursive_macro! { }`
51+
= note: to `my_recursive_macro ! ( ) ;`
52+
= note: expanding `my_recursive_macro! { }`
53+
= note: to `my_recursive_macro ! ( ) ;`
54+
= note: expanding `my_recursive_macro! { }`
55+
= note: to `my_recursive_macro ! ( ) ;`
56+
57+
note: trace_macro
58+
--> $DIR/trace_faulty_macros.rs:43:5
59+
|
60+
43 | my_faulty_macro!();
61+
| ^^^^^^^^^^^^^^^^^^^
62+
|
63+
= note: expanding `my_faulty_macro! { }`
64+
= note: to `my_faulty_macro ! ( bcd ) ;`
65+
= note: expanding `my_faulty_macro! { bcd }`
66+
67+
note: trace_macro
68+
--> $DIR/trace_faulty_macros.rs:44:5
69+
|
70+
44 | nested_pat_macro!();
71+
| ^^^^^^^^^^^^^^^^^^^^
72+
|
73+
= note: expanding `nested_pat_macro! { }`
74+
= note: to `nested_pat_macro ! ( inner ) ;`
75+
= note: expanding `nested_pat_macro! { inner }`
76+
= note: to `a | b | 1 ... 3 | _`
77+

0 commit comments

Comments
 (0)