Skip to content

Commit 152811d

Browse files
committed
Change expansion error to be non-fatal
Changes the error handler for inner attributes that replace the root with a non-module. Previously it would emit a fatal error. It now emits an empty expasion and a non-fatal error like the existing handler for a failed expansion.
1 parent 410114b commit 152811d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/librustc_expand/expand.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
364364
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
365365
}
366366
Some(ast::Item { span, kind, .. }) => {
367-
self.cx.span_fatal(
367+
krate.attrs = vec![];
368+
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
369+
self.cx.span_err(
368370
span,
369371
&format!(
370372
"expected crate top-level item to be a module after macro expansion, found a {}",

src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
// Test that using a macro to replace the entire crate tree with a non-'mod' item errors out nicely.
44
// `issue_59191::no_main` replaces whatever's passed in with `fn main() {}`.
55
#![feature(custom_inner_attributes)]
6+
//~^ ERROR `main` function not found in crate `issue_59191_replace_root_with_fn` [E0601]
67
#![issue_59191::no_main]
78
//~^ ERROR expected crate top-level item to be a module after macro expansion, found a function
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
error: expected crate top-level item to be a module after macro expansion, found a function
2-
--> $DIR/issue-59191-replace-root-with-fn.rs:6:1
2+
--> $DIR/issue-59191-replace-root-with-fn.rs:7:1
33
|
44
LL | #![issue_59191::no_main]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error[E0601]: `main` function not found in crate `issue_59191_replace_root_with_fn`
8+
--> $DIR/issue-59191-replace-root-with-fn.rs:5:1
9+
|
10+
LL | / #![feature(custom_inner_attributes)]
11+
LL | |
12+
LL | | #![issue_59191::no_main]
13+
| |________________________^ consider adding a `main` function to `$DIR/issue-59191-replace-root-with-fn.rs`
14+
15+
error: aborting due to 2 previous errors
816

17+
For more information about this error, try `rustc --explain E0601`.

0 commit comments

Comments
 (0)