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:
parent
410114b9d2
commit
152811d8bf
@ -364,7 +364,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
|||||||
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
|
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
|
||||||
}
|
}
|
||||||
Some(ast::Item { span, kind, .. }) => {
|
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,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"expected crate top-level item to be a module after macro expansion, found a {}",
|
"expected crate top-level item to be a module after macro expansion, found a {}",
|
||||||
|
@ -3,5 +3,6 @@
|
|||||||
// Test that using a macro to replace the entire crate tree with a non-'mod' item errors out nicely.
|
// 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() {}`.
|
// `issue_59191::no_main` replaces whatever's passed in with `fn main() {}`.
|
||||||
#![feature(custom_inner_attributes)]
|
#![feature(custom_inner_attributes)]
|
||||||
|
//~^ ERROR `main` function not found in crate `issue_59191_replace_root_with_fn` [E0601]
|
||||||
#![issue_59191::no_main]
|
#![issue_59191::no_main]
|
||||||
//~^ ERROR expected crate top-level item to be a module after macro expansion, found a function
|
//~^ ERROR expected crate top-level item to be a module after macro expansion, found a function
|
||||||
|
@ -1,8 +1,17 @@
|
|||||||
error: expected crate top-level item to be a module after macro expansion, found a function
|
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]
|
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`.
|
||||||
|
Loading…
Reference in New Issue
Block a user