Skip to content

Commit 8b71e0b

Browse files
committed
Better trace-macro and less span_err_fatal
1 parent 8bb7dba commit 8b71e0b

File tree

4 files changed

+15
-41
lines changed

4 files changed

+15
-41
lines changed

src/libsyntax/ext/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,16 @@ impl<'a> ExtCtxt<'a> {
792792
pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
793793
self.parse_sess.span_diagnostic.span_bug(sp, msg);
794794
}
795-
pub fn trace_macros_diag(&self) {
795+
pub fn trace_macros_diag(&mut self) {
796796
for (sp, notes) in self.expansions.iter() {
797797
let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
798798
for note in notes {
799799
db.note(note);
800800
}
801801
db.emit();
802802
}
803+
// Fixme: does this result in errors?
804+
self.expansions.clear();
803805
}
804806
pub fn bug(&self, msg: &str) -> ! {
805807
self.parse_sess.span_diagnostic.bug(msg);

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
384384
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
385385
let info = self.cx.current_expansion.mark.expn_info().unwrap();
386386
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
387-
let mut err = self.cx.struct_span_fatal(info.call_site,
387+
let mut err = self.cx.struct_span_err(info.call_site,
388388
&format!("recursion limit reached while expanding the macro `{}`",
389389
info.callee.name()));
390390
err.help(&format!(
@@ -640,6 +640,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
640640
Ok(expansion) => expansion,
641641
Err(mut err) => {
642642
err.emit();
643+
self.cx.trace_macros_diag();
643644
return kind.dummy(span);
644645
}
645646
};

src/test/ui/macros/trace_faulty_macros.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ macro_rules! my_faulty_macro {
1818
};
1919
}
2020

21-
macro_rules! nested_pat_macro {
21+
macro_rules! pat_macro {
2222
() => {
23-
nested_pat_macro!(inner);
23+
pat_macro!(A{a:a, b:0, c:_, ..});
24+
};
25+
($a:pat) => {
26+
$a
2427
};
25-
(inner) => {
26-
a | b | 1 ... 3 | _
27-
}
2828
}
2929

3030
macro_rules! my_recursive_macro {
@@ -41,11 +41,11 @@ macro_rules! my_macro {
4141

4242
fn main() {
4343
my_faulty_macro!();
44-
nested_pat_macro!();
4544
my_recursive_macro!();
4645
test!();
4746
non_exisiting!();
4847
derive!(Debug);
48+
let a = pat_macro!();
4949
}
5050

5151
#[my_macro]

src/test/ui/macros/trace_faulty_macros.stderr

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,21 @@ note: trace_macro
1717
= note: to `my_faulty_macro ! ( bcd ) ;`
1818
= note: expanding `my_faulty_macro! { bcd }`
1919

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-
2920
error: recursion limit reached while expanding the macro `my_recursive_macro`
3021
--> $DIR/trace_faulty_macros.rs:32:9
3122
|
3223
32 | my_recursive_macro!();
3324
| ^^^^^^^^^^^^^^^^^^^^^^
3425
...
35-
45 | my_recursive_macro!();
26+
44 | my_recursive_macro!();
3627
| ---------------------- in this macro invocation
3728
|
3829
= help: consider adding a `#![recursion_limit="8"]` attribute to your crate
3930

4031
note: trace_macro
41-
--> $DIR/trace_faulty_macros.rs:45:5
32+
--> $DIR/trace_faulty_macros.rs:44:5
4233
|
43-
45 | my_recursive_macro!();
34+
44 | my_recursive_macro!();
4435
| ^^^^^^^^^^^^^^^^^^^^^^
4536
|
4637
= note: expanding `my_recursive_macro! { }`
@@ -54,24 +45,4 @@ note: trace_macro
5445
= note: expanding `my_recursive_macro! { }`
5546
= note: to `my_recursive_macro ! ( ) ;`
5647

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-
48+

0 commit comments

Comments
 (0)