@@ -70,6 +70,17 @@ impl InheritConstStability {
7070 }
7171}
7272
73+ enum InheritStability {
74+ Yes ,
75+ No ,
76+ }
77+
78+ impl InheritStability {
79+ fn yes ( & self ) -> bool {
80+ matches ! ( self , InheritStability :: Yes )
81+ }
82+ }
83+
7384// A private tree-walker for producing an Index.
7485struct Annotator < ' a , ' tcx > {
7586 tcx : TyCtxt < ' tcx > ,
@@ -91,6 +102,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
91102 kind : AnnotationKind ,
92103 inherit_deprecation : InheritDeprecation ,
93104 inherit_const_stability : InheritConstStability ,
105+ inherit_from_parent : InheritStability ,
94106 visit_children : F ,
95107 ) where
96108 F : FnOnce ( & mut Self ) ,
@@ -131,12 +143,13 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
131143 }
132144
133145 if self . tcx . features ( ) . staged_api {
134- if let Some ( ..) = attrs. iter ( ) . find ( |a| self . tcx . sess . check_name ( a, sym:: deprecated) ) {
135- self . tcx . sess . span_err (
136- item_sp,
137- "`#[deprecated]` cannot be used in staged API; \
138- use `#[rustc_deprecated]` instead",
139- ) ;
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 ( ) ;
140153 }
141154 } else {
142155 self . recurse_with_stability_attrs (
@@ -185,7 +198,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
185198 if kind == AnnotationKind :: Prohibited
186199 || ( kind == AnnotationKind :: Container && stab. level . is_stable ( ) && is_deprecated)
187200 {
188- self . tcx . sess . span_err ( item_sp, "This stability annotation is useless" ) ;
201+ self . tcx . sess . span_err ( item_sp, "this stability annotation is useless" ) ;
189202 }
190203
191204 debug ! ( "annotate: found {:?}" , stab) ;
@@ -202,15 +215,15 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
202215 {
203216 match stab_v. parse :: < u64 > ( ) {
204217 Err ( _) => {
205- self . tcx . sess . span_err ( item_sp, "Invalid stability version found" ) ;
218+ self . tcx . sess . span_err ( item_sp, "invalid stability version found" ) ;
206219 break ;
207220 }
208221 Ok ( stab_vp) => match dep_v. parse :: < u64 > ( ) {
209222 Ok ( dep_vp) => match dep_vp. cmp ( & stab_vp) {
210223 Ordering :: Less => {
211224 self . tcx . sess . span_err (
212225 item_sp,
213- "An API can't be stabilized after it is deprecated" ,
226+ "an API can't be stabilized after it is deprecated" ,
214227 ) ;
215228 break ;
216229 }
@@ -221,7 +234,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
221234 if dep_v != "TBD" {
222235 self . tcx
223236 . sess
224- . span_err ( item_sp, "Invalid deprecation version found" ) ;
237+ . span_err ( item_sp, "invalid deprecation version found" ) ;
225238 }
226239 break ;
227240 }
@@ -237,7 +250,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
237250 if stab. is_none ( ) {
238251 debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
239252 if let Some ( stab) = self . parent_stab {
240- if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
253+ if inherit_deprecation. yes ( ) && stab. level . is_unstable ( )
254+ || inherit_from_parent. yes ( )
255+ {
241256 self . index . stab_map . insert ( hir_id, stab) ;
242257 }
243258 }
@@ -368,6 +383,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
368383 AnnotationKind :: Required ,
369384 InheritDeprecation :: Yes ,
370385 InheritConstStability :: No ,
386+ InheritStability :: Yes ,
371387 |_| { } ,
372388 )
373389 }
@@ -382,6 +398,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
382398 kind,
383399 InheritDeprecation :: Yes ,
384400 const_stab_inherit,
401+ InheritStability :: No ,
385402 |v| intravisit:: walk_item ( v, i) ,
386403 ) ;
387404 self . in_trait_impl = orig_in_trait_impl;
@@ -395,6 +412,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
395412 AnnotationKind :: Required ,
396413 InheritDeprecation :: Yes ,
397414 InheritConstStability :: No ,
415+ InheritStability :: No ,
398416 |v| {
399417 intravisit:: walk_trait_item ( v, ti) ;
400418 } ,
@@ -411,6 +429,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
411429 kind,
412430 InheritDeprecation :: Yes ,
413431 InheritConstStability :: No ,
432+ InheritStability :: No ,
414433 |v| {
415434 intravisit:: walk_impl_item ( v, ii) ;
416435 } ,
@@ -425,6 +444,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
425444 AnnotationKind :: Required ,
426445 InheritDeprecation :: Yes ,
427446 InheritConstStability :: No ,
447+ InheritStability :: Yes ,
428448 |v| {
429449 if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
430450 v. annotate (
@@ -434,6 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
434454 AnnotationKind :: Required ,
435455 InheritDeprecation :: Yes ,
436456 InheritConstStability :: No ,
457+ InheritStability :: No ,
437458 |_| { } ,
438459 ) ;
439460 }
@@ -451,6 +472,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
451472 AnnotationKind :: Required ,
452473 InheritDeprecation :: Yes ,
453474 InheritConstStability :: No ,
475+ InheritStability :: Yes ,
454476 |v| {
455477 intravisit:: walk_struct_field ( v, s) ;
456478 } ,
@@ -465,6 +487,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
465487 AnnotationKind :: Required ,
466488 InheritDeprecation :: Yes ,
467489 InheritConstStability :: No ,
490+ InheritStability :: No ,
468491 |v| {
469492 intravisit:: walk_foreign_item ( v, i) ;
470493 } ,
@@ -479,6 +502,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
479502 AnnotationKind :: Required ,
480503 InheritDeprecation :: Yes ,
481504 InheritConstStability :: No ,
505+ InheritStability :: No ,
482506 |_| { } ,
483507 ) ;
484508 }
@@ -499,6 +523,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
499523 kind,
500524 InheritDeprecation :: No ,
501525 InheritConstStability :: No ,
526+ InheritStability :: No ,
502527 |v| {
503528 intravisit:: walk_generic_param ( v, p) ;
504529 } ,
@@ -669,6 +694,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
669694 AnnotationKind :: Required ,
670695 InheritDeprecation :: Yes ,
671696 InheritConstStability :: No ,
697+ InheritStability :: No ,
672698 |v| intravisit:: walk_crate ( v, krate) ,
673699 ) ;
674700 }
0 commit comments