about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-03-17 11:30:53 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-03-24 06:28:56 +0100
commitc1ef1b3bca27709a6ddc40f0eab801f144c1b60c (patch)
tree0ccc063c1432a1e6d2933f6e0b1f17f80ae5c673
parentce8880d1d8b10cfaebc44449a37b6ad9fc628cb9 (diff)
downloadrust-c1ef1b3bca27709a6ddc40f0eab801f144c1b60c.tar.gz
rust-c1ef1b3bca27709a6ddc40f0eab801f144c1b60c.zip
defatalize ProcMacroDerive::expand
Also remove ExtCtxt::struct_span_fatal.
-rw-r--r--src/librustc_expand/base.rs3
-rw-r--r--src/librustc_expand/proc_macro.rs25
-rw-r--r--src/test/ui/proc-macro/derive-bad.rs8
-rw-r--r--src/test/ui/proc-macro/derive-bad.stderr26
-rw-r--r--src/test/ui/proc-macro/issue-36935.rs1
-rw-r--r--src/test/ui/proc-macro/issue-36935.stderr14
6 files changed, 44 insertions, 33 deletions
diff --git a/src/librustc_expand/base.rs b/src/librustc_expand/base.rs
index 4947730a4aa..c107a7f2409 100644
--- a/src/librustc_expand/base.rs
+++ b/src/librustc_expand/base.rs
@@ -1020,9 +1020,6 @@ impl<'a> ExtCtxt<'a> {
     pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> {
         self.parse_sess.span_diagnostic.struct_span_err(sp, msg)
     }
-    pub fn struct_span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> {
-        self.parse_sess.span_diagnostic.struct_span_fatal(sp, msg)
-    }
 
     /// Emit `msg` attached to `sp`, and stop compilation immediately.
     ///
diff --git a/src/librustc_expand/proc_macro.rs b/src/librustc_expand/proc_macro.rs
index 40b5e63756b..df7bf9438c3 100644
--- a/src/librustc_expand/proc_macro.rs
+++ b/src/librustc_expand/proc_macro.rs
@@ -5,7 +5,7 @@ use rustc_ast::ast::{self, ItemKind, MetaItemKind, NestedMetaItem};
 use rustc_ast::token;
 use rustc_ast::tokenstream::{self, TokenStream};
 use rustc_data_structures::sync::Lrc;
-use rustc_errors::{Applicability, ErrorReported, FatalError};
+use rustc_errors::{Applicability, ErrorReported};
 use rustc_span::symbol::sym;
 use rustc_span::{Span, DUMMY_SP};
 
@@ -86,8 +86,7 @@ impl MultiItemModifier for ProcMacroDerive {
             | Annotatable::Expr(_) => {
                 ecx.span_err(
                     span,
-                    "proc-macro derives may only be \
-                                    applied to a struct, enum, or union",
+                    "proc-macro derives may only be applied to a struct, enum, or union",
                 );
                 return ExpandResult::Ready(Vec::new());
             }
@@ -97,8 +96,7 @@ impl MultiItemModifier for ProcMacroDerive {
             _ => {
                 ecx.span_err(
                     span,
-                    "proc-macro derives may only be \
-                                    applied to a struct, enum, or union",
+                    "proc-macro derives may only be applied to a struct, enum, or union",
                 );
                 return ExpandResult::Ready(Vec::new());
             }
@@ -111,20 +109,16 @@ impl MultiItemModifier for ProcMacroDerive {
         let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
             Ok(stream) => stream,
             Err(e) => {
-                let msg = "proc-macro derive panicked";
-                let mut err = ecx.struct_span_fatal(span, msg);
+                let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
                 if let Some(s) = e.as_str() {
                     err.help(&format!("message: {}", s));
                 }
-
                 err.emit();
-                FatalError.raise();
+                return ExpandResult::Ready(vec![]);
             }
         };
 
         let error_count_before = ecx.parse_sess.span_diagnostic.err_count();
-        let msg = "proc-macro derive produced unparseable tokens";
-
         let mut parser =
             rustc_parse::stream_to_parser(ecx.parse_sess, stream, Some("proc-macro derive"));
         let mut items = vec![];
@@ -134,18 +128,15 @@ impl MultiItemModifier for ProcMacroDerive {
                 Ok(None) => break,
                 Ok(Some(item)) => items.push(Annotatable::Item(item)),
                 Err(mut err) => {
-                    // FIXME: handle this better
-                    err.cancel();
-                    ecx.struct_span_fatal(span, msg).emit();
-                    FatalError.raise();
+                    err.emit();
+                    break;
                 }
             }
         }
 
         // fail if there have been errors emitted
         if ecx.parse_sess.span_diagnostic.err_count() > error_count_before {
-            ecx.struct_span_fatal(span, msg).emit();
-            FatalError.raise();
+            ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit();
         }
 
         ExpandResult::Ready(items)
diff --git a/src/test/ui/proc-macro/derive-bad.rs b/src/test/ui/proc-macro/derive-bad.rs
index 62c0741b669..cb5188b5fb4 100644
--- a/src/test/ui/proc-macro/derive-bad.rs
+++ b/src/test/ui/proc-macro/derive-bad.rs
@@ -3,11 +3,9 @@
 #[macro_use]
 extern crate derive_bad;
 
-#[derive(
-    A
-)]
-//~^^ ERROR proc-macro derive produced unparseable tokens
+#[derive(A)]
+//~^ ERROR proc-macro derive produced unparseable tokens
 //~| ERROR expected `:`, found `}`
-struct A;
+struct A; //~ ERROR the name `A` is defined multiple times
 
 fn main() {}
diff --git a/src/test/ui/proc-macro/derive-bad.stderr b/src/test/ui/proc-macro/derive-bad.stderr
index 8667396c989..bc5ed981523 100644
--- a/src/test/ui/proc-macro/derive-bad.stderr
+++ b/src/test/ui/proc-macro/derive-bad.stderr
@@ -1,16 +1,28 @@
 error: expected `:`, found `}`
-  --> $DIR/derive-bad.rs:7:5
+  --> $DIR/derive-bad.rs:6:10
    |
-LL |     A
-   |     ^ expected `:`
+LL | #[derive(A)]
+   |          ^ expected `:`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: proc-macro derive produced unparseable tokens
-  --> $DIR/derive-bad.rs:7:5
+  --> $DIR/derive-bad.rs:6:10
    |
-LL |     A
-   |     ^
+LL | #[derive(A)]
+   |          ^
 
-error: aborting due to 2 previous errors
+error[E0428]: the name `A` is defined multiple times
+  --> $DIR/derive-bad.rs:9:1
+   |
+LL | #[derive(A)]
+   |          - previous definition of the type `A` here
+...
+LL | struct A;
+   | ^^^^^^^^^ `A` redefined here
+   |
+   = note: `A` must be defined only once in the type namespace of this module
+
+error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0428`.
diff --git a/src/test/ui/proc-macro/issue-36935.rs b/src/test/ui/proc-macro/issue-36935.rs
index f809592d5f4..5c43a564c00 100644
--- a/src/test/ui/proc-macro/issue-36935.rs
+++ b/src/test/ui/proc-macro/issue-36935.rs
@@ -5,6 +5,7 @@ extern crate test_macros;
 
 #[derive(Identity, Panic)] //~ ERROR proc-macro derive panicked
 struct Baz {
+    //~^ ERROR the name `Baz` is defined multiple times
     a: i32,
     b: i32,
 }
diff --git a/src/test/ui/proc-macro/issue-36935.stderr b/src/test/ui/proc-macro/issue-36935.stderr
index da4366eb668..2b2e28fdb2f 100644
--- a/src/test/ui/proc-macro/issue-36935.stderr
+++ b/src/test/ui/proc-macro/issue-36935.stderr
@@ -6,5 +6,17 @@ LL | #[derive(Identity, Panic)]
    |
    = help: message: panic-derive
 
-error: aborting due to previous error
+error[E0428]: the name `Baz` is defined multiple times
+  --> $DIR/issue-36935.rs:7:1
+   |
+LL | struct Baz {
+   | ^^^^^^^^^^
+   | |
+   | `Baz` redefined here
+   | previous definition of the type `Baz` here
+   |
+   = note: `Baz` must be defined only once in the type namespace of this module
+
+error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0428`.