Skip to content

Commit 4db157a

Browse files
committed
Allow attribute macro invocations at the crate root.
1 parent 5f6f838 commit 4db157a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/libsyntax/ext/expand.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,20 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
184184
fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate {
185185
let err_count = self.cx.parse_sess.span_diagnostic.err_count();
186186

187-
let mut krate_item = placeholder(ExpansionKind::Items, ast::DUMMY_NODE_ID)
188-
.make_items().pop().unwrap().unwrap();
189-
krate_item.node = ast::ItemKind::Mod(krate.module);
190-
let krate_item = Expansion::Items(SmallVector::one(P(krate_item)));
191-
192-
krate.module = match self.expand(krate_item).make_items().pop().unwrap().unwrap().node {
193-
ast::ItemKind::Mod(module) => module,
187+
let krate_item = Expansion::Items(SmallVector::one(P(ast::Item {
188+
attrs: krate.attrs,
189+
span: krate.span,
190+
node: ast::ItemKind::Mod(krate.module),
191+
ident: keywords::Invalid.ident(),
192+
id: ast::DUMMY_NODE_ID,
193+
vis: ast::Visibility::Public,
194+
})));
195+
196+
match self.expand(krate_item).make_items().pop().unwrap().unwrap() {
197+
ast::Item { attrs, node: ast::ItemKind::Mod(module), .. } => {
198+
krate.attrs = attrs;
199+
krate.module = module;
200+
},
194201
_ => unreachable!(),
195202
};
196203
krate.exported_macros = mem::replace(&mut self.cx.exported_macros, Vec::new());

0 commit comments

Comments
 (0)