-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix 59191 - ICE when macro replaces crate root with non-module item #68758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -363,7 +363,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> { | |
krate.attrs = vec![]; | ||
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true }; | ||
} | ||
_ => unreachable!(), | ||
Some(ast::Item { span, kind, .. }) => { | ||
self.cx.span_fatal( | ||
span, | ||
&format!( | ||
"expected crate top-level item to be a module after macro expansion, found a {}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Crate-level attribute macros aren't really expected to produce a module, they are just not supported at all and may result in nonsense and paradoxes. enum E {
#[test] // error: expected an inert attribute, found an attribute macro
V
}
fn main() {} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not urgent though, and I still hope to rewrite the macro invocation collector anyway. |
||
kind.descriptive_variant() | ||
), | ||
); | ||
} | ||
}; | ||
self.cx.trace_macros_diag(); | ||
krate | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// edition:2018 | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn no_main(_attrs: TokenStream, _input: TokenStream) -> TokenStream { | ||
let new_krate = r#" | ||
fn main() {} | ||
"#; | ||
new_krate.parse().unwrap() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// edition:2018 | ||
// aux-crate:issue_59191=issue-59191.rs | ||
// 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)] | ||
#![issue_59191::no_main] | ||
//~^ ERROR expected crate top-level item to be a module after macro expansion, found a function |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 | ||
| | ||
LL | #![issue_59191::no_main] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Uh oh!
There was an error while loading. Please reload this page.