From 276734d6a4997088b6d2e7416f5d4c07b4c8acf5 Mon Sep 17 00:00:00 2001 From: David Ross Date: Sat, 1 Feb 2020 18:04:07 -0800 Subject: [PATCH] Fix 59191 This adds an explicit error for when macros replace the crate root with a non-module item. --- src/librustc_expand/expand.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/librustc_expand/expand.rs b/src/librustc_expand/expand.rs index ea459064b09..1aa4f11a130 100644 --- a/src/librustc_expand/expand.rs +++ b/src/librustc_expand/expand.rs @@ -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 {}", + kind.descriptive_variant() + ), + ); + } }; self.cx.trace_macros_diag(); krate