diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index 1aa4f11a130..4e0fec9ce1d 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -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 {}", diff --git a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs index 039878af56e..a59cacb8bde 100644 --- a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs +++ b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.rs @@ -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 diff --git a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr index 1bda86551d4..e0a3caef9db 100644 --- a/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr +++ b/src/test/ui/proc-macro/issue-59191-replace-root-with-fn.stderr @@ -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`.