diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-09-21 09:20:42 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-09-21 09:24:06 +0000 |
| commit | 4db157af71dc32d38941b082d016c41adebc7a1d (patch) | |
| tree | f5adc7b5f4812cdc3b8cabb894e2ec580531c8ac /src/libsyntax/ext | |
| parent | 5f6f8384484382aeec5e1f647e18d37992966425 (diff) | |
| download | rust-4db157af71dc32d38941b082d016c41adebc7a1d.tar.gz rust-4db157af71dc32d38941b082d016c41adebc7a1d.zip | |
Allow attribute macro invocations at the crate root.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4e87d8ee9dd..e704934dba9 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -184,13 +184,20 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate { let err_count = self.cx.parse_sess.span_diagnostic.err_count(); - let mut krate_item = placeholder(ExpansionKind::Items, ast::DUMMY_NODE_ID) - .make_items().pop().unwrap().unwrap(); - krate_item.node = ast::ItemKind::Mod(krate.module); - let krate_item = Expansion::Items(SmallVector::one(P(krate_item))); - - krate.module = match self.expand(krate_item).make_items().pop().unwrap().unwrap().node { - ast::ItemKind::Mod(module) => module, + let krate_item = Expansion::Items(SmallVector::one(P(ast::Item { + attrs: krate.attrs, + span: krate.span, + node: ast::ItemKind::Mod(krate.module), + ident: keywords::Invalid.ident(), + id: ast::DUMMY_NODE_ID, + vis: ast::Visibility::Public, + }))); + + match self.expand(krate_item).make_items().pop().unwrap().unwrap() { + ast::Item { attrs, node: ast::ItemKind::Mod(module), .. } => { + krate.attrs = attrs; + krate.module = module; + }, _ => unreachable!(), }; krate.exported_macros = mem::replace(&mut self.cx.exported_macros, Vec::new()); |
