@@ -10,12 +10,11 @@ use rustc_ast::ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
10
10
use rustc_ast:: mut_visit:: * ;
11
11
use rustc_ast:: ptr:: P ;
12
12
use rustc_ast:: token;
13
- use rustc_ast:: tokenstream:: { TokenStream , TokenTree } ;
13
+ use rustc_ast:: tokenstream:: TokenStream ;
14
14
use rustc_ast:: util:: map_in_place:: MapInPlace ;
15
15
use rustc_ast:: visit:: { self , AssocCtxt , Visitor } ;
16
16
use rustc_ast_pretty:: pprust;
17
17
use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
18
- use rustc_data_structures:: sync:: Lrc ;
19
18
use rustc_errors:: { Applicability , FatalError , PResult } ;
20
19
use rustc_feature:: Features ;
21
20
use rustc_parse:: configure;
@@ -668,38 +667,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
668
667
SyntaxExtensionKind :: Attr ( expander) => {
669
668
self . gate_proc_macro_input ( & item) ;
670
669
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 {
698
673
self . cx . span_err ( span, "key-value macro attributes are not supported" ) ;
699
674
}
700
675
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)
703
678
}
704
679
SyntaxExtensionKind :: LegacyAttr ( expander) => {
705
680
match validate_attr:: parse_meta ( self . cx . parse_sess , & attr) {
0 commit comments