about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2017-09-02 17:21:13 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2017-09-02 17:21:13 +0200
commit8bb7dba9c7fee3e55a6aebe73a1e653a3af9f81a (patch)
treebc1c8ed7a0d830d5f5a1f9e57bf302a323c321d9
parent878013cd0c33e0aede78a6d0b5a579d9c2733844 (diff)
downloadrust-8bb7dba9c7fee3e55a6aebe73a1e653a3af9f81a.tar.gz
rust-8bb7dba9c7fee3e55a6aebe73a1e653a3af9f81a.zip
Dont abort on first macro error
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs4
-rw-r--r--src/test/ui/macros/assert_eq_trailing_comma.stderr2
-rw-r--r--src/test/ui/macros/assert_ne_trailing_comma.stderr2
-rw-r--r--src/test/ui/macros/trace_faulty_macros.rs55
-rw-r--r--src/test/ui/macros/trace_faulty_macros.stderr77
5 files changed, 139 insertions, 1 deletions
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 983b19c5bf0..be6571d7e55 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -172,7 +172,9 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
     }
 
     let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
-    cx.span_fatal(best_fail_spot.substitute_dummy(sp), &best_fail_msg);
+    cx.span_err(best_fail_spot.substitute_dummy(sp), &best_fail_msg);
+    cx.trace_macros_diag();
+    DummyResult::any(sp)
 }
 
 // Note that macro-by-example's input is also matched against a token tree:
diff --git a/src/test/ui/macros/assert_eq_trailing_comma.stderr b/src/test/ui/macros/assert_eq_trailing_comma.stderr
index ca590db90e4..1b46e94584e 100644
--- a/src/test/ui/macros/assert_eq_trailing_comma.stderr
+++ b/src/test/ui/macros/assert_eq_trailing_comma.stderr
@@ -4,3 +4,5 @@ error: unexpected end of macro invocation
 12 |     assert_eq!(1, 1,);
    |                    ^
 
+error: aborting due to previous error
+
diff --git a/src/test/ui/macros/assert_ne_trailing_comma.stderr b/src/test/ui/macros/assert_ne_trailing_comma.stderr
index ffabcaeb049..33d2cb0ed82 100644
--- a/src/test/ui/macros/assert_ne_trailing_comma.stderr
+++ b/src/test/ui/macros/assert_ne_trailing_comma.stderr
@@ -4,3 +4,5 @@ error: unexpected end of macro invocation
 12 |     assert_ne!(1, 2,);
    |                    ^
 
+error: aborting due to previous error
+
diff --git a/src/test/ui/macros/trace_faulty_macros.rs b/src/test/ui/macros/trace_faulty_macros.rs
new file mode 100644
index 00000000000..3b2d7ee5b75
--- /dev/null
+++ b/src/test/ui/macros/trace_faulty_macros.rs
@@ -0,0 +1,55 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: -Z trace-macros
+
+#![recursion_limit="4"]
+
+macro_rules! my_faulty_macro {
+    () => {
+        my_faulty_macro!(bcd);
+    };
+}
+
+macro_rules! nested_pat_macro {
+    () => {
+        nested_pat_macro!(inner);
+    };
+    (inner) => {
+        a | b | 1 ... 3 | _
+    }
+}
+
+macro_rules! my_recursive_macro {
+    () => {
+        my_recursive_macro!();
+    };
+}
+
+macro_rules! my_macro {
+    () => {
+        
+    };
+}
+
+fn main() {
+    my_faulty_macro!();
+    nested_pat_macro!();
+    my_recursive_macro!();
+    test!();
+    non_exisiting!();
+    derive!(Debug);
+}
+
+#[my_macro]
+fn use_bang_macro_as_attr(){}
+
+#[derive(Debug)]
+fn use_derive_macro_as_attr(){}
diff --git a/src/test/ui/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr
new file mode 100644
index 00000000000..1fd8511f181
--- /dev/null
+++ b/src/test/ui/macros/trace_faulty_macros.stderr
@@ -0,0 +1,77 @@
+error: no rules expected the token `bcd`
+  --> $DIR/trace_faulty_macros.rs:17:26
+   |
+17 |         my_faulty_macro!(bcd);
+   |                          ^^^
+...
+43 |     my_faulty_macro!();
+   |     ------------------- in this macro invocation
+
+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 }`
+
+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!();
+   |     ---------------------- 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
+   |
+45 |     my_recursive_macro!();
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: expanding `my_recursive_macro! {  }`
+   = note: to `my_recursive_macro ! (  ) ;`
+   = note: expanding `my_recursive_macro! {  }`
+   = note: to `my_recursive_macro ! (  ) ;`
+   = note: expanding `my_recursive_macro! {  }`
+   = note: to `my_recursive_macro ! (  ) ;`
+   = note: expanding `my_recursive_macro! {  }`
+   = note: to `my_recursive_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 | _`
+