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.
This commit is contained in:
David 2020-02-02 11:28:32 -08:00 committed by David Ross
parent 410114b9d2
commit 152811d8bf
3 changed files with 15 additions and 3 deletions

View File

@ -364,7 +364,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
}
Some(ast::Item { span, kind, .. }) => {
self.cx.span_fatal(
krate.attrs = vec![];
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
self.cx.span_err(
span,
&format!(
"expected crate top-level item to be a module after macro expansion, found a {}",

View File

@ -3,5 +3,6 @@
// Test that using a macro to replace the entire crate tree with a non-'mod' item errors out nicely.
// `issue_59191::no_main` replaces whatever's passed in with `fn main() {}`.
#![feature(custom_inner_attributes)]
//~^ ERROR `main` function not found in crate `issue_59191_replace_root_with_fn` [E0601]
#![issue_59191::no_main]
//~^ ERROR expected crate top-level item to be a module after macro expansion, found a function

View File

@ -1,8 +1,17 @@
error: expected crate top-level item to be a module after macro expansion, found a function
--> $DIR/issue-59191-replace-root-with-fn.rs:6:1
--> $DIR/issue-59191-replace-root-with-fn.rs:7:1
|
LL | #![issue_59191::no_main]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error[E0601]: `main` function not found in crate `issue_59191_replace_root_with_fn`
--> $DIR/issue-59191-replace-root-with-fn.rs:5:1
|
LL | / #![feature(custom_inner_attributes)]
LL | |
LL | | #![issue_59191::no_main]
| |________________________^ consider adding a `main` function to `$DIR/issue-59191-replace-root-with-fn.rs`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0601`.