Auto merge of #36618 - jseyfried:crate_root_attr_invoc, r=nrc
macros: allow attribute invocations at the crate root Fixes #36617. r? @nrc
This commit is contained in:
commit
a09cb57a73
2 changed files with 24 additions and 6 deletions
|
@ -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)));
|
||||
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,
|
||||
})));
|
||||
|
||||
krate.module = match self.expand(krate_item).make_items().pop().unwrap().unwrap().node {
|
||||
ast::ItemKind::Mod(module) => module,
|
||||
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());
|
||||
|
|
11
src/test/compile-fail/issue-36617.rs
Normal file
11
src/test/compile-fail/issue-36617.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![derive(Copy)] //~ ERROR `derive` may only be applied to structs, enums and unions
|
Loading…
Add table
Reference in a new issue