about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2017-09-02 18:13:25 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2017-09-02 18:13:25 +0200
commit8b71e0bbd596ada5d2e9c00d9249756d04607793 (patch)
tree7ba4e05e75dbe95cc13b4e85e6a992d131f47285
parent8bb7dba9c7fee3e55a6aebe73a1e653a3af9f81a (diff)
downloadrust-8b71e0bbd596ada5d2e9c00d9249756d04607793.tar.gz
rust-8b71e0bbd596ada5d2e9c00d9249756d04607793.zip
Better trace-macro and less span_err_fatal
-rw-r--r--src/libsyntax/ext/base.rs4
-rw-r--r--src/libsyntax/ext/expand.rs3
-rw-r--r--src/test/ui/macros/trace_faulty_macros.rs12
-rw-r--r--src/test/ui/macros/trace_faulty_macros.stderr37
4 files changed, 15 insertions, 41 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index e57d9c6fe89..402cdfe27fa 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -792,7 +792,7 @@ impl<'a> ExtCtxt<'a> {
     pub fn span_bug(&self, sp: Span, msg: &str) -> ! {
         self.parse_sess.span_diagnostic.span_bug(sp, msg);
     }
-    pub fn trace_macros_diag(&self) {
+    pub fn trace_macros_diag(&mut self) {
         for (sp, notes) in self.expansions.iter() {
             let mut db = self.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
             for note in notes {
@@ -800,6 +800,8 @@ impl<'a> ExtCtxt<'a> {
             }
             db.emit();
         }
+        // Fixme: does this result in errors?
+        self.expansions.clear();
     }
     pub fn bug(&self, msg: &str) -> ! {
         self.parse_sess.span_diagnostic.bug(msg);
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 414b248a267..7bc9f6b2d8f 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -384,7 +384,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
         if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
             let info = self.cx.current_expansion.mark.expn_info().unwrap();
             let suggested_limit = self.cx.ecfg.recursion_limit * 2;
-            let mut err = self.cx.struct_span_fatal(info.call_site,
+            let mut err = self.cx.struct_span_err(info.call_site,
                 &format!("recursion limit reached while expanding the macro `{}`",
                          info.callee.name()));
             err.help(&format!(
@@ -640,6 +640,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
             Ok(expansion) => expansion,
             Err(mut err) => {
                 err.emit();
+                self.cx.trace_macros_diag();
                 return kind.dummy(span);
             }
         };
diff --git a/src/test/ui/macros/trace_faulty_macros.rs b/src/test/ui/macros/trace_faulty_macros.rs
index 3b2d7ee5b75..a5b42dc191e 100644
--- a/src/test/ui/macros/trace_faulty_macros.rs
+++ b/src/test/ui/macros/trace_faulty_macros.rs
@@ -18,13 +18,13 @@ macro_rules! my_faulty_macro {
     };
 }
 
-macro_rules! nested_pat_macro {
+macro_rules! pat_macro {
     () => {
-        nested_pat_macro!(inner);
+        pat_macro!(A{a:a, b:0, c:_, ..});
+    };
+    ($a:pat) => {
+        $a
     };
-    (inner) => {
-        a | b | 1 ... 3 | _
-    }
 }
 
 macro_rules! my_recursive_macro {
@@ -41,11 +41,11 @@ macro_rules! my_macro {
 
 fn main() {
     my_faulty_macro!();
-    nested_pat_macro!();
     my_recursive_macro!();
     test!();
     non_exisiting!();
     derive!(Debug);
+    let a = pat_macro!();
 }
 
 #[my_macro]
diff --git a/src/test/ui/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr
index 1fd8511f181..bc289f8daa8 100644
--- a/src/test/ui/macros/trace_faulty_macros.stderr
+++ b/src/test/ui/macros/trace_faulty_macros.stderr
@@ -17,30 +17,21 @@ note: trace_macro
    = note: to `my_faulty_macro ! ( bcd ) ;`
    = note: expanding `my_faulty_macro! { bcd }`
 
-error: expected expression, found `_`
-  --> $DIR/trace_faulty_macros.rs:26:27
-   |
-26 |         a | b | 1 ... 3 | _
-   |                           ^
-...
-44 |     nested_pat_macro!();
-   |     -------------------- in this macro invocation
-
 error: recursion limit reached while expanding the macro `my_recursive_macro`
   --> $DIR/trace_faulty_macros.rs:32:9
    |
 32 |         my_recursive_macro!();
    |         ^^^^^^^^^^^^^^^^^^^^^^
 ...
-45 |     my_recursive_macro!();
+44 |     my_recursive_macro!();
    |     ---------------------- in this macro invocation
    |
    = help: consider adding a `#![recursion_limit="8"]` attribute to your crate
 
 note: trace_macro
-  --> $DIR/trace_faulty_macros.rs:45:5
+  --> $DIR/trace_faulty_macros.rs:44:5
    |
-45 |     my_recursive_macro!();
+44 |     my_recursive_macro!();
    |     ^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: expanding `my_recursive_macro! {  }`
@@ -54,24 +45,4 @@ note: trace_macro
    = note: expanding `my_recursive_macro! {  }`
    = note: to `my_recursive_macro ! (  ) ;`
 
-note: trace_macro
-  --> $DIR/trace_faulty_macros.rs:43:5
-   |
-43 |     my_faulty_macro!();
-   |     ^^^^^^^^^^^^^^^^^^^
-   |
-   = note: expanding `my_faulty_macro! {  }`
-   = note: to `my_faulty_macro ! ( bcd ) ;`
-   = note: expanding `my_faulty_macro! { bcd }`
-
-note: trace_macro
-  --> $DIR/trace_faulty_macros.rs:44:5
-   |
-44 |     nested_pat_macro!();
-   |     ^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: expanding `nested_pat_macro! {  }`
-   = note: to `nested_pat_macro ! ( inner ) ;`
-   = note: expanding `nested_pat_macro! { inner }`
-   = note: to `a | b | 1 ... 3 | _`
-
+   
\ No newline at end of file