@@ -337,12 +337,14 @@ struct MissingStabilityAnnotations<'a, 'tcx> {
337337}
338338
339339impl < ' 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 ) {
341341 let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
342342 let is_error =
343343 !self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
344344 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) ) ;
346348 }
347349 }
348350}
@@ -362,42 +364,42 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
362364 // optional. They inherit stability from their parents when unannotated.
363365 hir:: ItemKind :: Impl { of_trait : None , .. } | hir:: ItemKind :: ForeignMod ( ..) => { }
364366
365- _ => self . check_missing_stability ( i. hir_id , i. span , i . kind . descr ( ) ) ,
367+ _ => self . check_missing_stability ( i. hir_id , i. span ) ,
366368 }
367369
368370 intravisit:: walk_item ( self , i)
369371 }
370372
371373 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 ) ;
373375 intravisit:: walk_trait_item ( self , ti) ;
374376 }
375377
376378 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
377379 let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ) ) ;
378380 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 ) ;
380382 }
381383 intravisit:: walk_impl_item ( self , ii) ;
382384 }
383385
384386 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 ) ;
386388 intravisit:: walk_variant ( self , var, g, item_id) ;
387389 }
388390
389391 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 ) ;
391393 intravisit:: walk_struct_field ( self , s) ;
392394 }
393395
394396 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 ) ;
396398 intravisit:: walk_foreign_item ( self , i) ;
397399 }
398400
399401 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 ) ;
401403 }
402404}
403405
@@ -585,7 +587,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
585587 if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
586588 let krate = tcx. hir ( ) . krate ( ) ;
587589 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 ) ;
589591 intravisit:: walk_crate ( & mut missing, krate) ;
590592 krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
591593 }
0 commit comments