@@ -210,6 +210,10 @@ pub struct TraitData {
210210
211211impl TraitData {
212212 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 > > ) {
213217 let tr_loc @ ItemLoc { container : module_id, id : tree_id } = tr. lookup ( db) ;
214218 let item_tree = tree_id. item_tree ( db) ;
215219 let tr_def = & item_tree[ tree_id. value ] ;
@@ -229,17 +233,20 @@ impl TraitData {
229233 let mut collector =
230234 AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
231235 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+ )
243250 }
244251
245252 pub fn associated_types ( & self ) -> impl Iterator < Item = TypeAliasId > + ' _ {
@@ -280,7 +287,11 @@ pub struct ImplData {
280287
281288impl ImplData {
282289 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" ) ;
284295 let ItemLoc { container : module_id, id : tree_id } = id. lookup ( db) ;
285296
286297 let item_tree = tree_id. item_tree ( db) ;
@@ -293,10 +304,10 @@ impl ImplData {
293304 AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: ImplId ( id) ) ;
294305 collector. collect ( & item_tree, tree_id. tree_id ( ) , & impl_def. items ) ;
295306
296- let ( items, attribute_calls) = collector. finish ( ) ;
307+ let ( items, attribute_calls, diagnostics ) = collector. finish ( ) ;
297308 let items = items. into_iter ( ) . map ( |( _, item) | item) . collect ( ) ;
298309
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 ) )
300311 }
301312
302313 pub fn attribute_calls ( & self ) -> impl Iterator < Item = ( AstId < ast:: Item > , MacroCallId ) > + ' _ {
@@ -437,6 +448,7 @@ struct AssocItemCollector<'a> {
437448 db : & ' a dyn DefDatabase ,
438449 module_id : ModuleId ,
439450 def_map : Arc < DefMap > ,
451+ inactive_diagnostics : Vec < DefDiagnostic > ,
440452 container : ItemContainerId ,
441453 expander : Expander ,
442454
@@ -459,15 +471,17 @@ impl<'a> AssocItemCollector<'a> {
459471 expander : Expander :: new ( db, file_id, module_id) ,
460472 items : Vec :: new ( ) ,
461473 attr_calls : Vec :: new ( ) ,
474+ inactive_diagnostics : Vec :: new ( ) ,
462475 }
463476 }
464477
465478 fn finish (
466479 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 > ) {
468481 (
469482 self . items ,
470483 if self . attr_calls . is_empty ( ) { None } else { Some ( Box :: new ( self . attr_calls ) ) } ,
484+ self . inactive_diagnostics
471485 )
472486 }
473487
@@ -479,13 +493,12 @@ impl<'a> AssocItemCollector<'a> {
479493 ' items: for & item in assoc_items {
480494 let attrs = item_tree. attrs ( self . db , self . module_id . krate , ModItem :: from ( item) . into ( ) ) ;
481495 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 (
483497 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 ( ) ) ,
485499 attrs. cfg ( ) . unwrap ( ) ,
486500 self . expander . cfg_options ( ) . clone ( )
487501 ) ) ;
488- dbg ! ( "Ignoring assoc item!" ) ;
489502 continue ;
490503 }
491504
0 commit comments