@@ -337,12 +337,14 @@ struct MissingStabilityAnnotations<'a, 'tcx> {
337
337
}
338
338
339
339
impl < ' a , ' tcx > MissingStabilityAnnotations < ' a , ' tcx > {
340
- fn check_missing_stability ( & self , hir_id : HirId , span : Span , name : & str ) {
340
+ fn check_missing_stability ( & self , hir_id : HirId , span : Span ) {
341
341
let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
342
342
let is_error =
343
343
!self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
344
344
if is_error {
345
- self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , name) ) ;
345
+ let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
346
+ let descr = self . tcx . def_kind ( def_id) . descr ( def_id) ;
347
+ self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , descr) ) ;
346
348
}
347
349
}
348
350
}
@@ -362,42 +364,42 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
362
364
// optional. They inherit stability from their parents when unannotated.
363
365
hir:: ItemKind :: Impl { of_trait : None , .. } | hir:: ItemKind :: ForeignMod ( ..) => { }
364
366
365
- _ => self . check_missing_stability ( i. hir_id , i. span , i . kind . descr ( ) ) ,
367
+ _ => self . check_missing_stability ( i. hir_id , i. span ) ,
366
368
}
367
369
368
370
intravisit:: walk_item ( self , i)
369
371
}
370
372
371
373
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
372
- self . check_missing_stability ( ti. hir_id , ti. span , "item" ) ;
374
+ self . check_missing_stability ( ti. hir_id , ti. span ) ;
373
375
intravisit:: walk_trait_item ( self , ti) ;
374
376
}
375
377
376
378
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
377
379
let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ) ) ;
378
380
if self . tcx . impl_trait_ref ( impl_def_id) . is_none ( ) {
379
- self . check_missing_stability ( ii. hir_id , ii. span , "item" ) ;
381
+ self . check_missing_stability ( ii. hir_id , ii. span ) ;
380
382
}
381
383
intravisit:: walk_impl_item ( self , ii) ;
382
384
}
383
385
384
386
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
385
- self . check_missing_stability ( var. id , var. span , "variant" ) ;
387
+ self . check_missing_stability ( var. id , var. span ) ;
386
388
intravisit:: walk_variant ( self , var, g, item_id) ;
387
389
}
388
390
389
391
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
390
- self . check_missing_stability ( s. hir_id , s. span , "field" ) ;
392
+ self . check_missing_stability ( s. hir_id , s. span ) ;
391
393
intravisit:: walk_struct_field ( self , s) ;
392
394
}
393
395
394
396
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
395
- self . check_missing_stability ( i. hir_id , i. span , i . kind . descriptive_variant ( ) ) ;
397
+ self . check_missing_stability ( i. hir_id , i. span ) ;
396
398
intravisit:: walk_foreign_item ( self , i) ;
397
399
}
398
400
399
401
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
400
- self . check_missing_stability ( md. hir_id , md. span , "macro" ) ;
402
+ self . check_missing_stability ( md. hir_id , md. span ) ;
401
403
}
402
404
}
403
405
@@ -585,7 +587,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
585
587
if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
586
588
let krate = tcx. hir ( ) . krate ( ) ;
587
589
let mut missing = MissingStabilityAnnotations { tcx, access_levels } ;
588
- missing. check_missing_stability ( hir:: CRATE_HIR_ID , krate. item . span , "crate" ) ;
590
+ missing. check_missing_stability ( hir:: CRATE_HIR_ID , krate. item . span ) ;
589
591
intravisit:: walk_crate ( & mut missing, krate) ;
590
592
krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
591
593
}
0 commit comments