@@ -7,7 +7,6 @@ use crate::proc_macro::collect_derives;
77
88use rustc_ast_pretty:: pprust;
99use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
10- use rustc_data_structures:: sync:: Lrc ;
1110use rustc_errors:: { Applicability , FatalError , PResult } ;
1211use rustc_feature:: Features ;
1312use rustc_parse:: configure;
@@ -25,7 +24,7 @@ use syntax::ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
2524use syntax:: mut_visit:: * ;
2625use syntax:: ptr:: P ;
2726use syntax:: token;
28- use syntax:: tokenstream:: { TokenStream , TokenTree } ;
27+ use syntax:: tokenstream:: TokenStream ;
2928use syntax:: util:: map_in_place:: MapInPlace ;
3029use syntax:: visit:: { self , AssocCtxt , Visitor } ;
3130
@@ -668,36 +667,13 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
668667 SyntaxExtensionKind :: Attr ( expander) => {
669668 self . gate_proc_macro_input ( & item) ;
670669 self . gate_proc_macro_attr_item ( span, & item) ;
671- // `Annotatable` can be converted into tokens directly, but we are packing it
672- // into a nonterminal as a piece of AST to make the produced token stream
673- // look nicer in pretty-printed form. This may be no longer necessary.
674- let item_tok = TokenTree :: token (
675- token:: Interpolated ( Lrc :: new ( match item {
676- Annotatable :: Item ( item) => token:: NtItem ( item) ,
677- Annotatable :: TraitItem ( item)
678- | Annotatable :: ImplItem ( item)
679- | Annotatable :: ForeignItem ( item) => {
680- token:: NtItem ( P ( item. and_then ( ast:: AssocItem :: into_item) ) )
681- }
682- Annotatable :: Stmt ( stmt) => token:: NtStmt ( stmt. into_inner ( ) ) ,
683- Annotatable :: Expr ( expr) => token:: NtExpr ( expr) ,
684- Annotatable :: Arm ( ..)
685- | Annotatable :: Field ( ..)
686- | Annotatable :: FieldPat ( ..)
687- | Annotatable :: GenericParam ( ..)
688- | Annotatable :: Param ( ..)
689- | Annotatable :: StructField ( ..)
690- | Annotatable :: Variant ( ..) => panic ! ( "unexpected annotatable" ) ,
691- } ) ) ,
692- DUMMY_SP ,
693- )
694- . into ( ) ;
670+ let tokens = item. into_tokenstream ( self . cx . parse_sess ) ;
695671 let item = attr. unwrap_normal_item ( ) ;
696672 if let MacArgs :: Eq ( ..) = item. args {
697673 self . cx . span_err ( span, "key-value macro attributes are not supported" ) ;
698674 }
699675 let tok_result =
700- expander. expand ( self . cx , span, item. args . inner_tokens ( ) , item_tok ) ;
676+ expander. expand ( self . cx , span, item. args . inner_tokens ( ) , tokens ) ;
701677 self . parse_ast_fragment ( tok_result, fragment_kind, & item. path , span)
702678 }
703679 SyntaxExtensionKind :: LegacyAttr ( expander) => {
0 commit comments