@@ -70,6 +70,17 @@ impl InheritConstStability {
70
70
}
71
71
}
72
72
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
+
73
84
// A private tree-walker for producing an Index.
74
85
struct Annotator < ' a , ' tcx > {
75
86
tcx : TyCtxt < ' tcx > ,
@@ -91,6 +102,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
91
102
kind : AnnotationKind ,
92
103
inherit_deprecation : InheritDeprecation ,
93
104
inherit_const_stability : InheritConstStability ,
105
+ inherit_from_parent : InheritStability ,
94
106
visit_children : F ,
95
107
) where
96
108
F : FnOnce ( & mut Self ) ,
@@ -131,12 +143,13 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
131
143
}
132
144
133
145
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 ( ) ;
140
153
}
141
154
} else {
142
155
self . recurse_with_stability_attrs (
@@ -185,7 +198,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
185
198
if kind == AnnotationKind :: Prohibited
186
199
|| ( kind == AnnotationKind :: Container && stab. level . is_stable ( ) && is_deprecated)
187
200
{
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" ) ;
189
202
}
190
203
191
204
debug ! ( "annotate: found {:?}" , stab) ;
@@ -202,15 +215,15 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
202
215
{
203
216
match stab_v. parse :: < u64 > ( ) {
204
217
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" ) ;
206
219
break ;
207
220
}
208
221
Ok ( stab_vp) => match dep_v. parse :: < u64 > ( ) {
209
222
Ok ( dep_vp) => match dep_vp. cmp ( & stab_vp) {
210
223
Ordering :: Less => {
211
224
self . tcx . sess . span_err (
212
225
item_sp,
213
- "An API can't be stabilized after it is deprecated" ,
226
+ "an API can't be stabilized after it is deprecated" ,
214
227
) ;
215
228
break ;
216
229
}
@@ -221,7 +234,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
221
234
if dep_v != "TBD" {
222
235
self . tcx
223
236
. sess
224
- . span_err ( item_sp, "Invalid deprecation version found" ) ;
237
+ . span_err ( item_sp, "invalid deprecation version found" ) ;
225
238
}
226
239
break ;
227
240
}
@@ -237,7 +250,9 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
237
250
if stab. is_none ( ) {
238
251
debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
239
252
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
+ {
241
256
self . index . stab_map . insert ( hir_id, stab) ;
242
257
}
243
258
}
@@ -368,6 +383,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
368
383
AnnotationKind :: Required ,
369
384
InheritDeprecation :: Yes ,
370
385
InheritConstStability :: No ,
386
+ InheritStability :: Yes ,
371
387
|_| { } ,
372
388
)
373
389
}
@@ -382,6 +398,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
382
398
kind,
383
399
InheritDeprecation :: Yes ,
384
400
const_stab_inherit,
401
+ InheritStability :: No ,
385
402
|v| intravisit:: walk_item ( v, i) ,
386
403
) ;
387
404
self . in_trait_impl = orig_in_trait_impl;
@@ -395,6 +412,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
395
412
AnnotationKind :: Required ,
396
413
InheritDeprecation :: Yes ,
397
414
InheritConstStability :: No ,
415
+ InheritStability :: No ,
398
416
|v| {
399
417
intravisit:: walk_trait_item ( v, ti) ;
400
418
} ,
@@ -411,6 +429,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
411
429
kind,
412
430
InheritDeprecation :: Yes ,
413
431
InheritConstStability :: No ,
432
+ InheritStability :: No ,
414
433
|v| {
415
434
intravisit:: walk_impl_item ( v, ii) ;
416
435
} ,
@@ -425,6 +444,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
425
444
AnnotationKind :: Required ,
426
445
InheritDeprecation :: Yes ,
427
446
InheritConstStability :: No ,
447
+ InheritStability :: Yes ,
428
448
|v| {
429
449
if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
430
450
v. annotate (
@@ -434,6 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
434
454
AnnotationKind :: Required ,
435
455
InheritDeprecation :: Yes ,
436
456
InheritConstStability :: No ,
457
+ InheritStability :: No ,
437
458
|_| { } ,
438
459
) ;
439
460
}
@@ -451,6 +472,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
451
472
AnnotationKind :: Required ,
452
473
InheritDeprecation :: Yes ,
453
474
InheritConstStability :: No ,
475
+ InheritStability :: Yes ,
454
476
|v| {
455
477
intravisit:: walk_struct_field ( v, s) ;
456
478
} ,
@@ -465,6 +487,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
465
487
AnnotationKind :: Required ,
466
488
InheritDeprecation :: Yes ,
467
489
InheritConstStability :: No ,
490
+ InheritStability :: No ,
468
491
|v| {
469
492
intravisit:: walk_foreign_item ( v, i) ;
470
493
} ,
@@ -479,6 +502,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
479
502
AnnotationKind :: Required ,
480
503
InheritDeprecation :: Yes ,
481
504
InheritConstStability :: No ,
505
+ InheritStability :: No ,
482
506
|_| { } ,
483
507
) ;
484
508
}
@@ -499,6 +523,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
499
523
kind,
500
524
InheritDeprecation :: No ,
501
525
InheritConstStability :: No ,
526
+ InheritStability :: No ,
502
527
|v| {
503
528
intravisit:: walk_generic_param ( v, p) ;
504
529
} ,
@@ -669,6 +694,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
669
694
AnnotationKind :: Required ,
670
695
InheritDeprecation :: Yes ,
671
696
InheritConstStability :: No ,
697
+ InheritStability :: No ,
672
698
|v| intravisit:: walk_crate ( v, krate) ,
673
699
) ;
674
700
}
0 commit comments