@@ -10,12 +10,11 @@ use rustc_ast::ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
1010use rustc_ast:: mut_visit:: * ;
1111use rustc_ast:: ptr:: P ;
1212use rustc_ast:: token;
13- use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
13+ use rustc_ast:: tokenstream:: TokenStream ;
1414use rustc_ast:: util:: map_in_place:: MapInPlace ;
1515use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
1616use rustc_ast_pretty:: pprust;
1717use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
18- use rustc_data_structures:: sync:: Lrc ;
1918use rustc_errors:: { Applicability , FatalError , PResult } ;
2019use rustc_feature:: Features ;
2120use rustc_parse:: configure;
@@ -668,38 +667,14 @@ 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) | Annotatable :: ImplItem ( item) => {
678- token:: NtItem ( P ( item. and_then ( ast:: AssocItem :: into_item) ) )
679- }
680- Annotatable :: ForeignItem ( item) => {
681- token:: NtItem ( P ( item. and_then ( ast:: ForeignItem :: into_item) ) )
682- }
683- Annotatable :: Stmt ( stmt) => token:: NtStmt ( stmt. into_inner ( ) ) ,
684- Annotatable :: Expr ( expr) => token:: NtExpr ( expr) ,
685- Annotatable :: Arm ( ..)
686- | Annotatable :: Field ( ..)
687- | Annotatable :: FieldPat ( ..)
688- | Annotatable :: GenericParam ( ..)
689- | Annotatable :: Param ( ..)
690- | Annotatable :: StructField ( ..)
691- | Annotatable :: Variant ( ..) => panic ! ( "unexpected annotatable" ) ,
692- } ) ) ,
693- DUMMY_SP ,
694- )
695- . into ( ) ;
696- let item = attr. unwrap_normal_item ( ) ;
697- if let MacArgs :: Eq ( ..) = item. args {
670+ let tokens = item. into_tokens ( ) ;
671+ let attr_item = attr. unwrap_normal_item ( ) ;
672+ if let MacArgs :: Eq ( ..) = attr_item. args {
698673 self . cx . span_err ( span, "key-value macro attributes are not supported" ) ;
699674 }
700675 let tok_result =
701- expander. expand ( self . cx , span, item . args . inner_tokens ( ) , item_tok ) ;
702- self . parse_ast_fragment ( tok_result, fragment_kind, & item . path , span)
676+ expander. expand ( self . cx , span, attr_item . args . inner_tokens ( ) , tokens ) ;
677+ self . parse_ast_fragment ( tok_result, fragment_kind, & attr_item . path , span)
703678 }
704679 SyntaxExtensionKind :: LegacyAttr ( expander) => {
705680 match validate_attr:: parse_meta ( self . cx . parse_sess , & attr) {
0 commit comments