@@ -3,7 +3,6 @@ use crate::util::check_builtin_macro_attribute;
33use rustc_ast:: mut_visit:: { self , MutVisitor } ;
44use rustc_ast:: ptr:: P ;
55use rustc_ast:: { self as ast, AstLike } ;
6- use rustc_data_structures:: map_in_place:: MapInPlace ;
76use rustc_expand:: base:: { Annotatable , ExtCtxt } ;
87use rustc_expand:: config:: StripUnconfigured ;
98use rustc_expand:: configure;
@@ -43,57 +42,6 @@ impl CfgEval<'_> {
4342 self . cfg . configure ( node)
4443 }
4544
46- fn configure_foreign_mod ( & mut self , foreign_mod : & mut ast:: ForeignMod ) {
47- let ast:: ForeignMod { unsafety : _, abi : _, items } = foreign_mod;
48- items. flat_map_in_place ( |item| self . configure ( item) ) ;
49- }
50-
51- fn configure_variant_data ( & mut self , vdata : & mut ast:: VariantData ) {
52- match vdata {
53- ast:: VariantData :: Struct ( fields, ..) | ast:: VariantData :: Tuple ( fields, _) => {
54- fields. flat_map_in_place ( |field| self . configure ( field) )
55- }
56- ast:: VariantData :: Unit ( _) => { }
57- }
58- }
59-
60- fn configure_item_kind ( & mut self , item : & mut ast:: ItemKind ) {
61- match item {
62- ast:: ItemKind :: Struct ( def, _generics) | ast:: ItemKind :: Union ( def, _generics) => {
63- self . configure_variant_data ( def)
64- }
65- ast:: ItemKind :: Enum ( ast:: EnumDef { variants } , _generics) => {
66- variants. flat_map_in_place ( |variant| self . configure ( variant) ) ;
67- for variant in variants {
68- self . configure_variant_data ( & mut variant. data ) ;
69- }
70- }
71- _ => { }
72- }
73- }
74-
75- fn configure_expr_kind ( & mut self , expr_kind : & mut ast:: ExprKind ) {
76- match expr_kind {
77- ast:: ExprKind :: Match ( _m, arms) => {
78- arms. flat_map_in_place ( |arm| self . configure ( arm) ) ;
79- }
80- ast:: ExprKind :: Struct ( _path, fields, _base) => {
81- fields. flat_map_in_place ( |field| self . configure ( field) ) ;
82- }
83- _ => { }
84- }
85- }
86-
87- fn configure_pat ( & mut self , pat : & mut P < ast:: Pat > ) {
88- if let ast:: PatKind :: Struct ( _path, fields, _etc) = & mut pat. kind {
89- fields. flat_map_in_place ( |field| self . configure ( field) ) ;
90- }
91- }
92-
93- fn configure_fn_decl ( & mut self , fn_decl : & mut ast:: FnDecl ) {
94- fn_decl. inputs . flat_map_in_place ( |arg| self . configure ( arg) ) ;
95- }
96-
9745 crate fn fully_configure ( & mut self , item : Annotatable ) -> Annotatable {
9846 // Since the item itself has already been configured by the InvocationCollector,
9947 // we know that fold result vector will contain exactly one element
@@ -139,25 +87,13 @@ impl CfgEval<'_> {
13987}
14088
14189impl MutVisitor for CfgEval < ' _ > {
142- fn visit_foreign_mod ( & mut self , foreign_mod : & mut ast:: ForeignMod ) {
143- self . configure_foreign_mod ( foreign_mod) ;
144- mut_visit:: noop_visit_foreign_mod ( foreign_mod, self ) ;
145- }
146-
147- fn visit_item_kind ( & mut self , item : & mut ast:: ItemKind ) {
148- self . configure_item_kind ( item) ;
149- mut_visit:: noop_visit_item_kind ( item, self ) ;
150- }
151-
15290 fn visit_expr ( & mut self , expr : & mut P < ast:: Expr > ) {
15391 self . cfg . configure_expr ( expr) ;
154- self . configure_expr_kind ( & mut expr. kind ) ;
15592 mut_visit:: noop_visit_expr ( expr, self ) ;
15693 }
15794
15895 fn filter_map_expr ( & mut self , expr : P < ast:: Expr > ) -> Option < P < ast:: Expr > > {
15996 let mut expr = configure ! ( self , expr) ;
160- self . configure_expr_kind ( & mut expr. kind ) ;
16197 mut_visit:: noop_visit_expr ( & mut expr, self ) ;
16298 Some ( expr)
16399 }
@@ -185,13 +121,34 @@ impl MutVisitor for CfgEval<'_> {
185121 mut_visit:: noop_flat_map_assoc_item ( configure ! ( self , item) , self )
186122 }
187123
188- fn visit_pat ( & mut self , pat : & mut P < ast:: Pat > ) {
189- self . configure_pat ( pat) ;
190- mut_visit:: noop_visit_pat ( pat, self )
124+ fn flat_map_foreign_item (
125+ & mut self ,
126+ foreign_item : P < ast:: ForeignItem > ,
127+ ) -> SmallVec < [ P < ast:: ForeignItem > ; 1 ] > {
128+ mut_visit:: noop_flat_map_foreign_item ( configure ! ( self , foreign_item) , self )
129+ }
130+
131+ fn flat_map_arm ( & mut self , arm : ast:: Arm ) -> SmallVec < [ ast:: Arm ; 1 ] > {
132+ mut_visit:: noop_flat_map_arm ( configure ! ( self , arm) , self )
133+ }
134+
135+ fn flat_map_field ( & mut self , field : ast:: Field ) -> SmallVec < [ ast:: Field ; 1 ] > {
136+ mut_visit:: noop_flat_map_field ( configure ! ( self , field) , self )
137+ }
138+
139+ fn flat_map_field_pattern ( & mut self , fp : ast:: FieldPat ) -> SmallVec < [ ast:: FieldPat ; 1 ] > {
140+ mut_visit:: noop_flat_map_field_pattern ( configure ! ( self , fp) , self )
141+ }
142+
143+ fn flat_map_param ( & mut self , p : ast:: Param ) -> SmallVec < [ ast:: Param ; 1 ] > {
144+ mut_visit:: noop_flat_map_param ( configure ! ( self , p) , self )
145+ }
146+
147+ fn flat_map_struct_field ( & mut self , sf : ast:: StructField ) -> SmallVec < [ ast:: StructField ; 1 ] > {
148+ mut_visit:: noop_flat_map_struct_field ( configure ! ( self , sf) , self )
191149 }
192150
193- fn visit_fn_decl ( & mut self , mut fn_decl : & mut P < ast:: FnDecl > ) {
194- self . configure_fn_decl ( & mut fn_decl) ;
195- mut_visit:: noop_visit_fn_decl ( fn_decl, self ) ;
151+ fn flat_map_variant ( & mut self , variant : ast:: Variant ) -> SmallVec < [ ast:: Variant ; 1 ] > {
152+ mut_visit:: noop_flat_map_variant ( configure ! ( self , variant) , self )
196153 }
197154}
0 commit comments