Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c15de4

Browse files
committedMar 19, 2017
Auto merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
`TokenStream`-based attributes, paths in attribute and derive macro invocations This PR - refactors `Attribute` to use `Path` and `TokenStream` instead of `MetaItem`. - supports macro invocation paths for attribute procedural macros. - e.g. `#[::foo::attr_macro] struct S;`, `#[cfg_attr(all(), foo::attr_macro)] struct S;` - supports macro invocation paths for derive procedural macros. - e.g. `#[derive(foo::Bar, super::Baz)] struct S;` - supports arbitrary tokens as arguments to attribute procedural macros. - e.g. `#[foo::attr_macro arbitrary + tokens] struct S;` - supports using arbitrary tokens in "inert attributes" with derive procedural macros. - e.g. `#[derive(Foo)] struct S(#[inert arbitrary + tokens] i32);` where `#[proc_macro_derive(Foo, attributes(inert))]` r? @nrc
2 parents bfc49b1 + 85e02bd commit 9c15de4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+883
-539
lines changed
 

‎src/librustc/hir/check_attr.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ impl<'a> CheckAttrVisitor<'a> {
120120
}
121121

122122
fn check_attribute(&self, attr: &ast::Attribute, target: Target) {
123-
let name: &str = &attr.name().as_str();
124-
match name {
125-
"inline" => self.check_inline(attr, target),
126-
"repr" => self.check_repr(attr, target),
127-
_ => (),
123+
if let Some(name) = attr.name() {
124+
match &*name.as_str() {
125+
"inline" => self.check_inline(attr, target),
126+
"repr" => self.check_repr(attr, target),
127+
_ => (),
128+
}
128129
}
129130
}
130131
}

‎src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ impl<'a> LoweringContext<'a> {
12961296
let attrs = self.lower_attrs(&i.attrs);
12971297
let mut vis = self.lower_visibility(&i.vis);
12981298
if let ItemKind::MacroDef(ref tts) = i.node {
1299-
if i.attrs.iter().any(|attr| attr.name() == "macro_export") {
1299+
if i.attrs.iter().any(|attr| attr.path == "macro_export") {
13001300
self.exported_macros.push(hir::MacroDef {
13011301
name: name, attrs: attrs, id: i.id, span: i.span, body: tts.clone().into(),
13021302
});

0 commit comments

Comments
 (0)
Please sign in to comment.