2
2
3
3
use std:: sync:: Arc ;
4
4
5
- use hir_expand:: { name:: Name , AstId , ExpandResult , HirFileId , MacroCallId , MacroDefKind } ;
5
+ use hir_expand:: { name:: Name , AstId , ExpandResult , HirFileId , InFile , MacroCallId , MacroDefKind } ;
6
6
use smallvec:: SmallVec ;
7
7
use syntax:: ast;
8
8
@@ -12,7 +12,10 @@ use crate::{
12
12
db:: DefDatabase ,
13
13
intern:: Interned ,
14
14
item_tree:: { self , AssocItem , FnFlags , ItemTree , ItemTreeId , ModItem , Param , TreeId } ,
15
- nameres:: { attr_resolution:: ResolvedAttr , proc_macro:: ProcMacroKind , DefMap } ,
15
+ nameres:: {
16
+ attr_resolution:: ResolvedAttr , diagnostics:: DefDiagnostic , proc_macro:: ProcMacroKind ,
17
+ DefMap ,
18
+ } ,
16
19
type_ref:: { TraitRef , TypeBound , TypeRef } ,
17
20
visibility:: RawVisibility ,
18
21
AssocItemId , AstIdWithPath , ConstId , ConstLoc , FunctionId , FunctionLoc , HasModule , ImplId ,
@@ -210,6 +213,13 @@ pub struct TraitData {
210
213
211
214
impl TraitData {
212
215
pub ( crate ) fn trait_data_query ( db : & dyn DefDatabase , tr : TraitId ) -> Arc < TraitData > {
216
+ db. trait_data_with_diagnostics ( tr) . 0
217
+ }
218
+
219
+ pub ( crate ) fn trait_data_with_diagnostics_query (
220
+ db : & dyn DefDatabase ,
221
+ tr : TraitId ,
222
+ ) -> ( Arc < TraitData > , Arc < Vec < DefDiagnostic > > ) {
213
223
let tr_loc @ ItemLoc { container : module_id, id : tree_id } = tr. lookup ( db) ;
214
224
let item_tree = tree_id. item_tree ( db) ;
215
225
let tr_def = & item_tree[ tree_id. value ] ;
@@ -229,17 +239,20 @@ impl TraitData {
229
239
let mut collector =
230
240
AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: TraitId ( tr) ) ;
231
241
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
- } )
242
+ let ( items, attribute_calls, diagnostics) = collector. finish ( ) ;
243
+
244
+ (
245
+ Arc :: new ( TraitData {
246
+ name,
247
+ attribute_calls,
248
+ items,
249
+ is_auto,
250
+ is_unsafe,
251
+ visibility,
252
+ skip_array_during_method_dispatch,
253
+ } ) ,
254
+ Arc :: new ( diagnostics) ,
255
+ )
243
256
}
244
257
245
258
pub fn associated_types ( & self ) -> impl Iterator < Item = TypeAliasId > + ' _ {
@@ -280,7 +293,14 @@ pub struct ImplData {
280
293
281
294
impl ImplData {
282
295
pub ( crate ) fn impl_data_query ( db : & dyn DefDatabase , id : ImplId ) -> Arc < ImplData > {
283
- let _p = profile:: span ( "impl_data_query" ) ;
296
+ db. impl_data_with_diagnostics ( id) . 0
297
+ }
298
+
299
+ pub ( crate ) fn impl_data_with_diagnostics_query (
300
+ db : & dyn DefDatabase ,
301
+ id : ImplId ,
302
+ ) -> ( Arc < ImplData > , Arc < Vec < DefDiagnostic > > ) {
303
+ let _p = profile:: span ( "impl_data_with_diagnostics_query" ) ;
284
304
let ItemLoc { container : module_id, id : tree_id } = id. lookup ( db) ;
285
305
286
306
let item_tree = tree_id. item_tree ( db) ;
@@ -293,10 +313,13 @@ impl ImplData {
293
313
AssocItemCollector :: new ( db, module_id, tree_id. file_id ( ) , ItemContainerId :: ImplId ( id) ) ;
294
314
collector. collect ( & item_tree, tree_id. tree_id ( ) , & impl_def. items ) ;
295
315
296
- let ( items, attribute_calls) = collector. finish ( ) ;
316
+ let ( items, attribute_calls, diagnostics ) = collector. finish ( ) ;
297
317
let items = items. into_iter ( ) . map ( |( _, item) | item) . collect ( ) ;
298
318
299
- Arc :: new ( ImplData { target_trait, self_ty, items, is_negative, attribute_calls } )
319
+ (
320
+ Arc :: new ( ImplData { target_trait, self_ty, items, is_negative, attribute_calls } ) ,
321
+ Arc :: new ( diagnostics) ,
322
+ )
300
323
}
301
324
302
325
pub fn attribute_calls ( & self ) -> impl Iterator < Item = ( AstId < ast:: Item > , MacroCallId ) > + ' _ {
@@ -437,6 +460,7 @@ struct AssocItemCollector<'a> {
437
460
db : & ' a dyn DefDatabase ,
438
461
module_id : ModuleId ,
439
462
def_map : Arc < DefMap > ,
463
+ inactive_diagnostics : Vec < DefDiagnostic > ,
440
464
container : ItemContainerId ,
441
465
expander : Expander ,
442
466
@@ -459,15 +483,21 @@ impl<'a> AssocItemCollector<'a> {
459
483
expander : Expander :: new ( db, file_id, module_id) ,
460
484
items : Vec :: new ( ) ,
461
485
attr_calls : Vec :: new ( ) ,
486
+ inactive_diagnostics : Vec :: new ( ) ,
462
487
}
463
488
}
464
489
465
490
fn finish (
466
491
self ,
467
- ) -> ( Vec < ( Name , AssocItemId ) > , Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ) {
492
+ ) -> (
493
+ Vec < ( Name , AssocItemId ) > ,
494
+ Option < Box < Vec < ( AstId < ast:: Item > , MacroCallId ) > > > ,
495
+ Vec < DefDiagnostic > ,
496
+ ) {
468
497
(
469
498
self . items ,
470
499
if self . attr_calls . is_empty ( ) { None } else { Some ( Box :: new ( self . attr_calls ) ) } ,
500
+ self . inactive_diagnostics ,
471
501
)
472
502
}
473
503
@@ -479,6 +509,12 @@ impl<'a> AssocItemCollector<'a> {
479
509
' items: for & item in assoc_items {
480
510
let attrs = item_tree. attrs ( self . db , self . module_id . krate , ModItem :: from ( item) . into ( ) ) ;
481
511
if !attrs. is_cfg_enabled ( self . expander . cfg_options ( ) ) {
512
+ self . inactive_diagnostics . push ( DefDiagnostic :: unconfigured_code (
513
+ self . module_id . local_id ,
514
+ InFile :: new ( self . expander . current_file_id ( ) , item. ast_id ( & item_tree) . upcast ( ) ) ,
515
+ attrs. cfg ( ) . unwrap ( ) ,
516
+ self . expander . cfg_options ( ) . clone ( ) ,
517
+ ) ) ;
482
518
continue ;
483
519
}
484
520
0 commit comments