Skip to content

Commit a98ea5a

Browse files
committed
defatalize ProcMacroDerive::expand
Also remove ExtCtxt::struct_span_fatal.
1 parent 4bea03d commit a98ea5a

File tree

6 files changed

+44
-33
lines changed

6 files changed

+44
-33
lines changed

src/librustc_expand/base.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,6 @@ impl<'a> ExtCtxt<'a> {
10131013
pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> {
10141014
self.parse_sess.span_diagnostic.struct_span_err(sp, msg)
10151015
}
1016-
pub fn struct_span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> DiagnosticBuilder<'a> {
1017-
self.parse_sess.span_diagnostic.struct_span_fatal(sp, msg)
1018-
}
10191016

10201017
/// Emit `msg` attached to `sp`, and stop compilation immediately.
10211018
///

src/librustc_expand/proc_macro.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::ast::{self, ItemKind, MetaItemKind, NestedMetaItem};
55
use rustc_ast::token;
66
use rustc_ast::tokenstream::{self, TokenStream};
77
use rustc_data_structures::sync::Lrc;
8-
use rustc_errors::{Applicability, ErrorReported, FatalError};
8+
use rustc_errors::{Applicability, ErrorReported};
99
use rustc_span::symbol::sym;
1010
use rustc_span::{Span, DUMMY_SP};
1111

@@ -86,8 +86,7 @@ impl MultiItemModifier for ProcMacroDerive {
8686
| Annotatable::Expr(_) => {
8787
ecx.span_err(
8888
span,
89-
"proc-macro derives may only be \
90-
applied to a struct, enum, or union",
89+
"proc-macro derives may only be applied to a struct, enum, or union",
9190
);
9291
return ExpandResult::Ready(Vec::new());
9392
}
@@ -97,8 +96,7 @@ impl MultiItemModifier for ProcMacroDerive {
9796
_ => {
9897
ecx.span_err(
9998
span,
100-
"proc-macro derives may only be \
101-
applied to a struct, enum, or union",
99+
"proc-macro derives may only be applied to a struct, enum, or union",
102100
);
103101
return ExpandResult::Ready(Vec::new());
104102
}
@@ -111,20 +109,16 @@ impl MultiItemModifier for ProcMacroDerive {
111109
let stream = match self.client.run(&EXEC_STRATEGY, server, input) {
112110
Ok(stream) => stream,
113111
Err(e) => {
114-
let msg = "proc-macro derive panicked";
115-
let mut err = ecx.struct_span_fatal(span, msg);
112+
let mut err = ecx.struct_span_err(span, "proc-macro derive panicked");
116113
if let Some(s) = e.as_str() {
117114
err.help(&format!("message: {}", s));
118115
}
119-
120116
err.emit();
121-
FatalError.raise();
117+
return ExpandResult::Ready(vec![]);
122118
}
123119
};
124120

125121
let error_count_before = ecx.parse_sess.span_diagnostic.err_count();
126-
let msg = "proc-macro derive produced unparseable tokens";
127-
128122
let mut parser =
129123
rustc_parse::stream_to_parser(ecx.parse_sess, stream, Some("proc-macro derive"));
130124
let mut items = vec![];
@@ -134,18 +128,15 @@ impl MultiItemModifier for ProcMacroDerive {
134128
Ok(None) => break,
135129
Ok(Some(item)) => items.push(Annotatable::Item(item)),
136130
Err(mut err) => {
137-
// FIXME: handle this better
138-
err.cancel();
139-
ecx.struct_span_fatal(span, msg).emit();
140-
FatalError.raise();
131+
err.emit();
132+
break;
141133
}
142134
}
143135
}
144136

145137
// fail if there have been errors emitted
146138
if ecx.parse_sess.span_diagnostic.err_count() > error_count_before {
147-
ecx.struct_span_fatal(span, msg).emit();
148-
FatalError.raise();
139+
ecx.struct_span_err(span, "proc-macro derive produced unparseable tokens").emit();
149140
}
150141

151142
ExpandResult::Ready(items)

src/test/ui/proc-macro/derive-bad.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
#[macro_use]
44
extern crate derive_bad;
55

6-
#[derive(
7-
A
8-
)]
9-
//~^^ ERROR proc-macro derive produced unparseable tokens
6+
#[derive(A)]
7+
//~^ ERROR proc-macro derive produced unparseable tokens
108
//~| ERROR expected `:`, found `}`
11-
struct A;
9+
struct A; //~ ERROR the name `A` is defined multiple times
1210

1311
fn main() {}
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
error: expected `:`, found `}`
2-
--> $DIR/derive-bad.rs:7:5
2+
--> $DIR/derive-bad.rs:6:10
33
|
4-
LL | A
5-
| ^ expected `:`
4+
LL | #[derive(A)]
5+
| ^ expected `:`
66
|
77
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: proc-macro derive produced unparseable tokens
10-
--> $DIR/derive-bad.rs:7:5
10+
--> $DIR/derive-bad.rs:6:10
1111
|
12-
LL | A
13-
| ^
12+
LL | #[derive(A)]
13+
| ^
1414

15-
error: aborting due to 2 previous errors
15+
error[E0428]: the name `A` is defined multiple times
16+
--> $DIR/derive-bad.rs:9:1
17+
|
18+
LL | #[derive(A)]
19+
| - previous definition of the type `A` here
20+
...
21+
LL | struct A;
22+
| ^^^^^^^^^ `A` redefined here
23+
|
24+
= note: `A` must be defined only once in the type namespace of this module
25+
26+
error: aborting due to 3 previous errors
1627

28+
For more information about this error, try `rustc --explain E0428`.

src/test/ui/proc-macro/issue-36935.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ extern crate test_macros;
55

66
#[derive(Identity, Panic)] //~ ERROR proc-macro derive panicked
77
struct Baz {
8+
//~^ ERROR the name `Baz` is defined multiple times
89
a: i32,
910
b: i32,
1011
}

src/test/ui/proc-macro/issue-36935.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,17 @@ LL | #[derive(Identity, Panic)]
66
|
77
= help: message: panic-derive
88

9-
error: aborting due to previous error
9+
error[E0428]: the name `Baz` is defined multiple times
10+
--> $DIR/issue-36935.rs:7:1
11+
|
12+
LL | struct Baz {
13+
| ^^^^^^^^^^
14+
| |
15+
| `Baz` redefined here
16+
| previous definition of the type `Baz` here
17+
|
18+
= note: `Baz` must be defined only once in the type namespace of this module
19+
20+
error: aborting due to 2 previous errors
1021

22+
For more information about this error, try `rustc --explain E0428`.

0 commit comments

Comments
 (0)