diff options
| author | bors <bors@rust-lang.org> | 2016-09-22 06:29:23 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-22 06:29:23 -0700 |
| commit | a09cb57a737fcea6bad33ca4e4ec8e3e97c712e2 (patch) | |
| tree | 6ceaec6e96364c947929d3f66623d7c9212d7b4b /src/libsyntax | |
| parent | b2627b080a2cdf29dbabcecac89ecf80fa56ca63 (diff) | |
| parent | f4fa62f4f2b984ca97e7d68dbf8c2f3cf88866c5 (diff) | |
| download | rust-a09cb57a737fcea6bad33ca4e4ec8e3e97c712e2.tar.gz rust-a09cb57a737fcea6bad33ca4e4ec8e3e97c712e2.zip | |
Auto merge of #36618 - jseyfried:crate_root_attr_invoc, r=nrc
macros: allow attribute invocations at the crate root Fixes #36617. r? @nrc
Diffstat (limited to 'src/libsyntax')
| -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 db0183a8b3a..5b291fb8dac 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()); |
