@@ -210,6 +210,10 @@ pub struct TraitData {
210
210
211
211
impl TraitData {
212
212
pub ( crate ) fn trait_data_query ( db : & dyn DefDatabase , tr : TraitId ) -> Arc < TraitData > {
213
+ db. trait_data_with_diagnostics ( tr) . 0
214
+ }
215
+
216
+ pub ( crate ) fn trait_data_with_diagnostics_query ( db : & dyn DefDatabase , tr : TraitId ) -> ( Arc < TraitData > , Arc < Vec < DefDiagnostic > > ) {
213
217
let tr_loc @ ItemLoc { container : module_id, id : tree_id } = tr. lookup ( db) ;
214
218
let item_tree = tree_id. item_tree ( db) ;
215
219
let tr_def = & item_tree[ tree_id. value ] ;
@@ -229,17 +233,20 @@ impl TraitData {
229
233
let mut collector =
230
234
AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
231
235
collector. collect ( & item_tree, tree_id. tree_id ( ) , & tr_def. items ) ;
232
- let ( items, attribute_calls) = collector. finish ( ) ;
233
-
234
- Arc :: new ( TraitData {
235
- name,
236
- attribute_calls,
237
- items,
238
- is_auto,
239
- is_unsafe,
240
- visibility,
241
- skip_array_during_method_dispatch,
242
- } )
236
+ let ( items, attribute_calls, diagnostics) = collector. finish ( ) ;
237
+
238
+ (
239
+ Arc :: new ( TraitData {
240
+ name,
241
+ attribute_calls,
242
+ items,
243
+ is_auto,
244
+ is_unsafe,
245
+ visibility,
246
+ skip_array_during_method_dispatch,
247
+ } ) ,
248
+ Arc :: new ( diagnostics)
249
+ )
243
250
}
244
251
245
252
pub fn associated_types ( & self ) -> impl Iterator < Item = TypeAliasId > + ' _ {
@@ -280,7 +287,11 @@ pub struct ImplData {
280
287
281
288
impl ImplData {
282
289
pub ( crate ) fn impl_data_query ( db : & dyn DefDatabase , id : ImplId ) -> Arc < ImplData > {
283
- let _p = profile:: span ( "impl_data_query" ) ;
290
+ db. impl_data_with_diagnostics ( id) . 0
291
+ }
292
+
293
+ pub ( crate ) fn impl_data_with_diagnostics_query ( db : & dyn DefDatabase , id : ImplId ) -> ( Arc < ImplData > , Arc < Vec < DefDiagnostic > > ) {
294
+ let _p = profile:: span ( "impl_data_with_diagnostics_query" ) ;
284
295
let ItemLoc { container : module_id, id : tree_id } = id. lookup ( db) ;
285
296
286
297
let item_tree = tree_id. item_tree ( db) ;
@@ -293,10 +304,10 @@ impl ImplData {
293
304
AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: ImplId ( id) ) ;
294
305
collector. collect ( & item_tree, tree_id. tree_id ( ) , & impl_def. items ) ;
295
306
296
- let ( items, attribute_calls) = collector. finish ( ) ;
307
+ let ( items, attribute_calls, diagnostics ) = collector. finish ( ) ;
297
308
let items = items. into_iter ( ) . map ( |( _, item) | item) . collect ( ) ;
298
309
299
- Arc :: new ( ImplData { target_trait, self_ty, items, is_negative, attribute_calls } )
310
+ ( Arc :: new ( ImplData { target_trait, self_ty, items, is_negative, attribute_calls } ) , Arc :: new ( diagnostics ) )
300
311
}
301
312
302
313
pub fn attribute_calls ( & self ) -> impl Iterator < Item = ( AstId < ast:: Item > , MacroCallId ) > + ' _ {
@@ -437,6 +448,7 @@ struct AssocItemCollector<'a> {
437
448
db : & ' a dyn DefDatabase ,
438
449
module_id : ModuleId ,
439
450
def_map : Arc < DefMap > ,
451
+ inactive_diagnostics : Vec < DefDiagnostic > ,
440
452
container : ItemContainerId ,
441
453
expander : Expander ,
442
454
@@ -459,15 +471,17 @@ impl<'a> AssocItemCollector<'a> {
459
471
expander : Expander :: new ( db, file_id, module_id) ,
460
472
items : Vec :: new ( ) ,
461
473
attr_calls : Vec :: new ( ) ,
474
+ inactive_diagnostics : Vec :: new ( ) ,
462
475
}
463
476
}
464
477
465
478
fn finish (
466
479
self ,
467
- ) -> ( Vec < ( Name , AssocItemId ) > , Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ) {
480
+ ) -> ( Vec < ( Name , AssocItemId ) > , Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > , Vec < DefDiagnostic > ) {
468
481
(
469
482
self . items ,
470
483
if self . attr_calls . is_empty ( ) { None } else { Some ( Box :: new ( self . attr_calls ) ) } ,
484
+ self . inactive_diagnostics
471
485
)
472
486
}
473
487
@@ -479,13 +493,12 @@ impl<'a> AssocItemCollector<'a> {
479
493
' items: for & item in assoc_items {
480
494
let attrs = item_tree. attrs ( self . db , self . module_id . krate , ModItem :: from ( item) . into ( ) ) ;
481
495
if !attrs. is_cfg_enabled ( self . expander . cfg_options ( ) ) {
482
- self . def_map . push_diagnostic ( DefDiagnostic :: unconfigured_code (
496
+ self . inactive_diagnostics . push ( DefDiagnostic :: unconfigured_code (
483
497
self . module_id . local_id ,
484
- InFile :: new ( tree_id . file_id ( ) , item. ast_id ( & item_tree) . upcast ( ) ) ,
498
+ InFile :: new ( self . expander . current_file_id ( ) , item. ast_id ( & item_tree) . upcast ( ) ) ,
485
499
attrs. cfg ( ) . unwrap ( ) ,
486
500
self . expander . cfg_options ( ) . clone ( )
487
501
) ) ;
488
- dbg ! ( "Ignoring assoc item!" ) ;
489
502
continue ;
490
503
}
491
504
0 commit comments