@@ -147,29 +147,10 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
147
147
Ok ( self . file_map )
148
148
}
149
149
150
- /// Visit `cfg_if` macro and look for module declarations.
151
- fn visit_cfg_if ( & mut self , item : Cow < ' ast , ast:: Item > ) -> Result < ( ) , ModuleResolutionError > {
152
- let mut visitor = visitor:: CfgIfVisitor :: new ( self . psess ) ;
153
- visitor. visit_item ( & item) ;
154
- for module_item in visitor. mods ( ) {
155
- if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = module_item. item . kind {
156
- self . visit_sub_mod (
157
- & module_item. item ,
158
- Module :: new (
159
- module_item. item . span ,
160
- Some ( Cow :: Owned ( sub_mod_kind. clone ( ) ) ) ,
161
- Cow :: Owned ( ThinVec :: new ( ) ) ,
162
- Cow :: Owned ( ast:: AttrVec :: new ( ) ) ,
163
- ) ,
164
- ) ?;
165
- }
166
- }
167
- Ok ( ( ) )
168
- }
169
-
170
- fn visit_cfg_match ( & mut self , item : Cow < ' ast , ast:: Item > ) -> Result < ( ) , ModuleResolutionError > {
171
- let mut visitor = visitor:: CfgMatchVisitor :: new ( self . psess ) ;
172
- visitor. visit_item ( & item) ;
150
+ /// Visit calls of well known macros and look for module declarations.
151
+ fn visit_mac_call ( & mut self , mac : & ast:: MacCall ) -> Result < ( ) , ModuleResolutionError > {
152
+ let mut visitor = visitor:: KnownMacroVisitor :: new ( self . psess ) ;
153
+ visitor. visit_mac_call ( mac) ;
173
154
for module_item in visitor. mods ( ) {
174
155
if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = module_item. item . kind {
175
156
self . visit_sub_mod (
@@ -192,14 +173,8 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
192
173
items : ThinVec < rustc_ast:: ptr:: P < ast:: Item > > ,
193
174
) -> Result < ( ) , ModuleResolutionError > {
194
175
for item in items {
195
- if is_cfg_if ( & item) {
196
- self . visit_cfg_if ( Cow :: Owned ( item. into_inner ( ) ) ) ?;
197
- continue ;
198
- }
199
-
200
- if is_cfg_match ( & item) {
201
- self . visit_cfg_match ( Cow :: Owned ( item. into_inner ( ) ) ) ?;
202
- continue ;
176
+ if let ast:: ItemKind :: MacCall ( ref mac) = item. kind {
177
+ self . visit_mac_call ( mac) ?;
203
178
}
204
179
205
180
if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = item. kind {
@@ -224,12 +199,8 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> {
224
199
items : & ' ast [ rustc_ast:: ptr:: P < ast:: Item > ] ,
225
200
) -> Result < ( ) , ModuleResolutionError > {
226
201
for item in items {
227
- if is_cfg_if ( item) {
228
- self . visit_cfg_if ( Cow :: Borrowed ( item) ) ?;
229
- }
230
-
231
- if is_cfg_match ( item) {
232
- self . visit_cfg_match ( Cow :: Borrowed ( item) ) ?;
202
+ if let ast:: ItemKind :: MacCall ( ref mac) = item. kind {
203
+ self . visit_mac_call ( mac) ?;
233
204
}
234
205
235
206
if let ast:: ItemKind :: Mod ( _, ref sub_mod_kind) = item. kind {
@@ -589,24 +560,3 @@ fn path_value(attr: &ast::Attribute) -> Option<Symbol> {
589
560
fn find_path_value ( attrs : & [ ast:: Attribute ] ) -> Option < Symbol > {
590
561
attrs. iter ( ) . flat_map ( path_value) . next ( )
591
562
}
592
-
593
- fn is_macro_name ( mac : & ast:: MacCall , name : & str ) -> bool {
594
- mac. path
595
- . segments
596
- . last ( )
597
- . map_or ( false , |segment| segment. ident . name == Symbol :: intern ( name) )
598
- }
599
-
600
- fn is_cfg_if ( item : & ast:: Item ) -> bool {
601
- match item. kind {
602
- ast:: ItemKind :: MacCall ( ref mac) => is_macro_name ( mac, "cfg_if" ) ,
603
- _ => false ,
604
- }
605
- }
606
-
607
- fn is_cfg_match ( item : & ast:: Item ) -> bool {
608
- match item. kind {
609
- ast:: ItemKind :: MacCall ( ref mac) => is_macro_name ( mac, "cfg_match" ) ,
610
- _ => false ,
611
- }
612
- }
0 commit comments