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
This commit is contained in:
@@ -489,7 +489,8 @@ pub fn noop_fold_attribute<T: Folder>(attr: Attribute, fld: &mut T) -> Option<At
|
||||
Some(Attribute {
|
||||
id: attr.id,
|
||||
style: attr.style,
|
||||
value: fld.fold_meta_item(attr.value),
|
||||
path: fld.fold_path(attr.path),
|
||||
tokens: fld.fold_tts(attr.tokens),
|
||||
is_sugared_doc: attr.is_sugared_doc,
|
||||
span: fld.new_span(attr.span),
|
||||
})
|
||||
@@ -612,7 +613,7 @@ pub fn noop_fold_interpolated<T: Folder>(nt: token::Nonterminal, fld: &mut T)
|
||||
token::NtExpr(expr) => token::NtExpr(fld.fold_expr(expr)),
|
||||
token::NtTy(ty) => token::NtTy(fld.fold_ty(ty)),
|
||||
token::NtIdent(id) => token::NtIdent(Spanned::<Ident>{node: fld.fold_ident(id.node), ..id}),
|
||||
token::NtMeta(meta_item) => token::NtMeta(fld.fold_meta_item(meta_item)),
|
||||
token::NtMeta(meta) => token::NtMeta(fld.fold_meta_item(meta)),
|
||||
token::NtPath(path) => token::NtPath(fld.fold_path(path)),
|
||||
token::NtTT(tt) => token::NtTT(fld.fold_tt(tt)),
|
||||
token::NtArm(arm) => token::NtArm(fld.fold_arm(arm)),
|
||||
@@ -1371,7 +1372,7 @@ mod tests {
|
||||
matches_codepattern,
|
||||
"matches_codepattern",
|
||||
pprust::to_string(|s| fake_print_crate(s, &folded_crate)),
|
||||
"#[a]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string());
|
||||
"#[zz]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}".to_string());
|
||||
}
|
||||
|
||||
// even inside macro defs....
|
||||
|
||||
Reference in New Issue
Block a user