@@ -7,7 +7,6 @@ use crate::proc_macro::collect_derives;
7
7
8
8
use rustc_ast_pretty:: pprust;
9
9
use rustc_attr:: { self as attr, is_builtin_attr, HasAttrs } ;
10
- use rustc_data_structures:: sync:: Lrc ;
11
10
use rustc_errors:: { Applicability , FatalError , PResult } ;
12
11
use rustc_feature:: Features ;
13
12
use rustc_parse:: configure;
@@ -25,7 +24,7 @@ use syntax::ast::{ItemKind, MacArgs, MacStmtStyle, StmtKind};
25
24
use syntax:: mut_visit:: * ;
26
25
use syntax:: ptr:: P ;
27
26
use syntax:: token;
28
- use syntax:: tokenstream:: { TokenStream , TokenTree } ;
27
+ use syntax:: tokenstream:: TokenStream ;
29
28
use syntax:: util:: map_in_place:: MapInPlace ;
30
29
use syntax:: visit:: { self , AssocCtxt , Visitor } ;
31
30
@@ -668,36 +667,13 @@ 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)
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 ) ;
695
671
let item = attr. unwrap_normal_item ( ) ;
696
672
if let MacArgs :: Eq ( ..) = item. args {
697
673
self . cx . span_err ( span, "key-value macro attributes are not supported" ) ;
698
674
}
699
675
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 ) ;
701
677
self . parse_ast_fragment ( tok_result, fragment_kind, & item. path , span)
702
678
}
703
679
SyntaxExtensionKind :: LegacyAttr ( expander) => {
0 commit comments