Skip to content

Commit 276734d

Browse files
committed
Fix 59191
This adds an explicit error for when macros replace the crate root with a non-module item.
1 parent 6c0b779 commit 276734d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/librustc_expand/expand.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,15 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
363363
krate.attrs = vec![];
364364
krate.module = ast::Mod { inner: orig_mod_span, items: vec![], inline: true };
365365
}
366-
_ => unreachable!(),
366+
Some(ast::Item { span, kind, .. }) => {
367+
self.cx.span_fatal(
368+
span,
369+
&format!(
370+
"expected crate top-level item to be a module after macro expansion, found a {}",
371+
kind.descriptive_variant()
372+
),
373+
);
374+
}
367375
};
368376
self.cx.trace_macros_diag();
369377
krate

0 commit comments

Comments
 (0)