@@ -97,7 +97,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
9797 fn annotate < F > (
9898 & mut self ,
9999 hir_id : HirId ,
100- item_sp : Span ,
101100 kind : AnnotationKind ,
102101 inherit_deprecation : InheritDeprecation ,
103102 inherit_const_stability : InheritConstStability ,
@@ -142,16 +141,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
142141 }
143142 }
144143
145- if self . tcx . features ( ) . staged_api {
146- if let Some ( a) = attrs. iter ( ) . find ( |a| self . tcx . sess . check_name ( a, sym:: deprecated) ) {
147- self . tcx
148- . sess
149- . struct_span_err ( a. span , "`#[deprecated]` cannot be used in staged API" )
150- . span_label ( a. span , "use `#[rustc_deprecated]` instead" )
151- . span_label ( item_sp, "" )
152- . emit ( ) ;
153- }
154- } else {
144+ if !self . tcx . features ( ) . staged_api {
155145 self . recurse_with_stability_attrs (
156146 depr. map ( |( d, _) | DeprecationEntry :: local ( d, hir_id) ) ,
157147 None ,
@@ -161,6 +151,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
161151 return ;
162152 }
163153
154+ let item_sp = self . tcx . hir ( ) . span_with_body ( hir_id) ;
155+ if let Some ( a) = attrs. iter ( ) . find ( |a| self . tcx . sess . check_name ( a, sym:: deprecated) ) {
156+ self . tcx
157+ . sess
158+ . struct_span_err ( a. span , "`#[deprecated]` cannot be used in staged API" )
159+ . span_label ( a. span , "use `#[rustc_deprecated]` instead" )
160+ . span_label ( item_sp, "" )
161+ . emit ( ) ;
162+ }
163+
164164 let ( stab, const_stab) = attr:: find_stability ( & self . tcx . sess , attrs, item_sp) ;
165165
166166 let const_stab = const_stab. map ( |( const_stab, _) | {
@@ -385,7 +385,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
385385 if let Some ( ctor_hir_id) = sd. ctor_hir_id ( ) {
386386 self . annotate (
387387 ctor_hir_id,
388- i. span ,
389388 AnnotationKind :: Required ,
390389 InheritDeprecation :: Yes ,
391390 InheritConstStability :: No ,
@@ -399,7 +398,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
399398
400399 self . annotate (
401400 i. hir_id ( ) ,
402- i. span ,
403401 kind,
404402 InheritDeprecation :: Yes ,
405403 const_stab_inherit,
@@ -412,7 +410,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
412410 fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
413411 self . annotate (
414412 ti. hir_id ( ) ,
415- ti. span ,
416413 AnnotationKind :: Required ,
417414 InheritDeprecation :: Yes ,
418415 InheritConstStability :: No ,
@@ -428,7 +425,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
428425 if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
429426 self . annotate (
430427 ii. hir_id ( ) ,
431- ii. span ,
432428 kind,
433429 InheritDeprecation :: Yes ,
434430 InheritConstStability :: No ,
@@ -440,10 +436,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
440436 }
441437
442438 fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
443- let var_span = self . tcx . hir ( ) . span ( var. id ) ;
444439 self . annotate (
445440 var. id ,
446- var_span,
447441 AnnotationKind :: Required ,
448442 InheritDeprecation :: Yes ,
449443 InheritConstStability :: No ,
@@ -452,7 +446,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
452446 if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
453447 v. annotate (
454448 ctor_hir_id,
455- var_span,
456449 AnnotationKind :: Required ,
457450 InheritDeprecation :: Yes ,
458451 InheritConstStability :: No ,
@@ -467,10 +460,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
467460 }
468461
469462 fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
470- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
471463 self . annotate (
472464 s. hir_id ,
473- span,
474465 AnnotationKind :: Required ,
475466 InheritDeprecation :: Yes ,
476467 InheritConstStability :: No ,
@@ -484,7 +475,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
484475 fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
485476 self . annotate (
486477 i. hir_id ( ) ,
487- i. span ,
488478 AnnotationKind :: Required ,
489479 InheritDeprecation :: Yes ,
490480 InheritConstStability :: No ,
@@ -496,10 +486,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
496486 }
497487
498488 fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
499- let span = self . tcx . hir ( ) . span ( md. hir_id ( ) ) ;
500489 self . annotate (
501490 md. hir_id ( ) ,
502- span,
503491 AnnotationKind :: Required ,
504492 InheritDeprecation :: Yes ,
505493 InheritConstStability :: No ,
@@ -517,10 +505,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
517505 _ => AnnotationKind :: Prohibited ,
518506 } ;
519507
520- let span = self . tcx . hir ( ) . span ( p. hir_id ) ;
521508 self . annotate (
522509 p. hir_id ,
523- span,
524510 kind,
525511 InheritDeprecation :: No ,
526512 InheritConstStability :: No ,
@@ -538,23 +524,25 @@ struct MissingStabilityAnnotations<'tcx> {
538524}
539525
540526impl < ' tcx > MissingStabilityAnnotations < ' tcx > {
541- fn check_missing_stability ( & self , hir_id : HirId , span : Span ) {
527+ fn check_missing_stability ( & self , hir_id : HirId ) {
542528 let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
543529 let is_error =
544530 !self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
545531 if is_error {
546532 let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
547533 let descr = self . tcx . def_kind ( def_id) . descr ( def_id. to_def_id ( ) ) ;
534+ let span = self . tcx . hir ( ) . span_with_body ( hir_id) ;
548535 self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , descr) ) ;
549536 }
550537 }
551538
552- fn check_missing_const_stability ( & self , hir_id : HirId , span : Span ) {
539+ fn check_missing_const_stability ( & self , hir_id : HirId ) {
553540 let stab_map = self . tcx . stability ( ) ;
554541 let stab = stab_map. local_stability ( hir_id) ;
555542 if stab. map_or ( false , |stab| stab. level . is_stable ( ) ) {
556543 let const_stab = stab_map. local_const_stability ( hir_id) ;
557544 if const_stab. is_none ( ) {
545+ let span = self . tcx . hir ( ) . span_with_body ( hir_id) ;
558546 self . tcx . sess . span_err (
559547 span,
560548 "`#[stable]` const functions must also be either \
@@ -582,53 +570,50 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
582570 hir:: ItemKind :: Impl ( hir:: Impl { of_trait: None , .. } )
583571 | hir:: ItemKind :: ForeignMod { .. }
584572 ) {
585- self . check_missing_stability ( i. hir_id ( ) , i . span ) ;
573+ self . check_missing_stability ( i. hir_id ( ) ) ;
586574 }
587575
588576 // Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
589577 // `rustc_const_stable`.
590578 if self . tcx . features ( ) . staged_api
591579 && matches ! ( & i. kind, hir:: ItemKind :: Fn ( sig, ..) if sig. header. is_const( ) )
592580 {
593- self . check_missing_const_stability ( i. hir_id ( ) , i . span ) ;
581+ self . check_missing_const_stability ( i. hir_id ( ) ) ;
594582 }
595583
596584 intravisit:: walk_item ( self , i)
597585 }
598586
599587 fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
600- self . check_missing_stability ( ti. hir_id ( ) , ti . span ) ;
588+ self . check_missing_stability ( ti. hir_id ( ) ) ;
601589 intravisit:: walk_trait_item ( self , ti) ;
602590 }
603591
604592 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
605593 let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ( ) ) ) ;
606594 if self . tcx . impl_trait_ref ( impl_def_id) . is_none ( ) {
607- self . check_missing_stability ( ii. hir_id ( ) , ii . span ) ;
595+ self . check_missing_stability ( ii. hir_id ( ) ) ;
608596 }
609597 intravisit:: walk_impl_item ( self , ii) ;
610598 }
611599
612600 fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
613- let span = self . tcx . hir ( ) . span ( var. id ) ;
614- self . check_missing_stability ( var. id , span) ;
601+ self . check_missing_stability ( var. id ) ;
615602 intravisit:: walk_variant ( self , var, g, item_id) ;
616603 }
617604
618605 fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
619- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
620- self . check_missing_stability ( s. hir_id , span) ;
606+ self . check_missing_stability ( s. hir_id ) ;
621607 intravisit:: walk_struct_field ( self , s) ;
622608 }
623609
624610 fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
625- self . check_missing_stability ( i. hir_id ( ) , i . span ) ;
611+ self . check_missing_stability ( i. hir_id ( ) ) ;
626612 intravisit:: walk_foreign_item ( self , i) ;
627613 }
628614
629615 fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
630- let span = self . tcx . hir ( ) . span ( md. hir_id ( ) ) ;
631- self . check_missing_stability ( md. hir_id ( ) , span) ;
616+ self . check_missing_stability ( md. hir_id ( ) ) ;
632617 }
633618
634619 // Note that we don't need to `check_missing_stability` for default generic parameters,
@@ -693,7 +678,6 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
693678
694679 annotator. annotate (
695680 hir:: CRATE_HIR_ID ,
696- tcx. hir ( ) . span ( hir:: CRATE_HIR_ID ) ,
697681 AnnotationKind :: Required ,
698682 InheritDeprecation :: Yes ,
699683 InheritConstStability :: No ,
@@ -892,7 +876,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
892876 if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
893877 let krate = tcx. hir ( ) . krate ( ) ;
894878 let mut missing = MissingStabilityAnnotations { tcx, access_levels } ;
895- missing. check_missing_stability ( hir:: CRATE_HIR_ID , tcx . hir ( ) . span ( hir :: CRATE_HIR_ID ) ) ;
879+ missing. check_missing_stability ( hir:: CRATE_HIR_ID ) ;
896880 intravisit:: walk_crate ( & mut missing, krate) ;
897881 krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
898882 }
0 commit comments