File tree Expand file tree Collapse file tree 4 files changed +15
-22
lines changed Expand file tree Collapse file tree 4 files changed +15
-22
lines changed Original file line number Diff line number Diff line change @@ -118,11 +118,12 @@ fn lower_enum(
118
118
module_id : ModuleId ,
119
119
) {
120
120
let expander = CfgExpander :: new ( db, ast. file_id , module_id. krate ) ;
121
- let variants =
122
- ast. value . variant_list ( ) . into_iter ( ) . flat_map ( |it| it. variants ( ) ) . filter ( |var| {
123
- let attrs = expander. parse_attrs ( var) ;
124
- expander. is_cfg_enabled ( & attrs)
125
- } ) ;
121
+ let variants = ast
122
+ . value
123
+ . variant_list ( )
124
+ . into_iter ( )
125
+ . flat_map ( |it| it. variants ( ) )
126
+ . filter ( |var| expander. is_cfg_enabled ( var) ) ;
126
127
for var in variants {
127
128
trace. alloc (
128
129
|| var. clone ( ) ,
@@ -215,8 +216,7 @@ fn lower_struct(
215
216
match & ast. value {
216
217
ast:: StructKind :: Tuple ( fl) => {
217
218
for ( i, fd) in fl. fields ( ) . enumerate ( ) {
218
- let attrs = expander. parse_attrs ( & fd) ;
219
- if !expander. is_cfg_enabled ( & attrs) {
219
+ if !expander. is_cfg_enabled ( & fd) {
220
220
continue ;
221
221
}
222
222
@@ -233,8 +233,7 @@ fn lower_struct(
233
233
}
234
234
ast:: StructKind :: Record ( fl) => {
235
235
for fd in fl. fields ( ) {
236
- let attrs = expander. parse_attrs ( & fd) ;
237
- if !expander. is_cfg_enabled ( & attrs) {
236
+ if !expander. is_cfg_enabled ( & fd) {
238
237
continue ;
239
238
}
240
239
Original file line number Diff line number Diff line change @@ -60,7 +60,8 @@ impl CfgExpander {
60
60
Attrs :: new ( owner, & self . hygiene )
61
61
}
62
62
63
- pub ( crate ) fn is_cfg_enabled ( & self , attrs : & Attrs ) -> bool {
63
+ pub ( crate ) fn is_cfg_enabled ( & self , owner : & dyn ast:: AttrsOwner ) -> bool {
64
+ let attrs = self . parse_attrs ( owner) ;
64
65
attrs. is_cfg_enabled ( & self . cfg_options )
65
66
}
66
67
}
@@ -141,12 +142,8 @@ impl Expander {
141
142
InFile { file_id : self . current_file_id , value }
142
143
}
143
144
144
- pub ( crate ) fn parse_attrs ( & self , owner : & dyn ast:: AttrsOwner ) -> Attrs {
145
- self . cfg_expander . parse_attrs ( owner)
146
- }
147
-
148
- pub ( crate ) fn is_cfg_enabled ( & self , attrs : & Attrs ) -> bool {
149
- self . cfg_expander . is_cfg_enabled ( attrs)
145
+ pub ( crate ) fn is_cfg_enabled ( & self , owner : & dyn ast:: AttrsOwner ) -> bool {
146
+ self . cfg_expander . is_cfg_enabled ( owner)
150
147
}
151
148
152
149
fn parse_path ( & mut self , path : ast:: Path ) -> Option < Path > {
Original file line number Diff line number Diff line change @@ -162,8 +162,7 @@ impl ExprCollector<'_> {
162
162
163
163
fn collect_expr ( & mut self , expr : ast:: Expr ) -> ExprId {
164
164
let syntax_ptr = AstPtr :: new ( & expr) ;
165
- let attrs = self . expander . parse_attrs ( & expr) ;
166
- if !self . expander . is_cfg_enabled ( & attrs) {
165
+ if !self . expander . is_cfg_enabled ( & expr) {
167
166
return self . missing_expr ( ) ;
168
167
}
169
168
match expr {
@@ -329,8 +328,7 @@ impl ExprCollector<'_> {
329
328
. fields ( )
330
329
. inspect ( |field| field_ptrs. push ( AstPtr :: new ( field) ) )
331
330
. filter_map ( |field| {
332
- let attrs = self . expander . parse_attrs ( & field) ;
333
- if !self . expander . is_cfg_enabled ( & attrs) {
331
+ if !self . expander . is_cfg_enabled ( & field) {
334
332
return None ;
335
333
}
336
334
let name = field. field_name ( ) ?. as_name ( ) ;
Original file line number Diff line number Diff line change @@ -335,8 +335,7 @@ fn collect_items(
335
335
. filter_map ( |item_node| match item_node {
336
336
ast:: ImplItem :: FnDef ( it) => {
337
337
let name = it. name ( ) . map_or_else ( Name :: missing, |it| it. as_name ( ) ) ;
338
- let attrs = expander. parse_attrs ( & it) ;
339
- if !expander. is_cfg_enabled ( & attrs) {
338
+ if !expander. is_cfg_enabled ( & it) {
340
339
return None ;
341
340
}
342
341
let def = FunctionLoc { container, ast_id : AstId :: new ( file_id, items. ast_id ( & it) ) }
You can’t perform that action at this time.
0 commit comments