@@ -68,6 +68,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
68
68
attrs : & [ Attribute ] ,
69
69
item_sp : Span ,
70
70
kind : AnnotationKind ,
71
+ inherit_deprecation : bool ,
71
72
visit_children : F ,
72
73
) where
73
74
F : FnOnce ( & mut Self ) ,
@@ -102,8 +103,11 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
102
103
// If parent is deprecated and we're not, inherit this by merging
103
104
// deprecated_since and its reason.
104
105
if let Some ( parent_stab) = self . parent_stab {
105
- if parent_stab. rustc_depr . is_some ( ) && stab. rustc_depr . is_none ( ) {
106
- stab. rustc_depr = parent_stab. rustc_depr
106
+ if inherit_deprecation
107
+ && parent_stab. rustc_depr . is_some ( )
108
+ && stab. rustc_depr . is_none ( )
109
+ {
110
+ stab. rustc_depr = parent_stab. rustc_depr . clone ( )
107
111
}
108
112
}
109
113
@@ -155,7 +159,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
155
159
// Instability is inherited from the parent: if something is unstable,
156
160
// everything inside it should also be considered unstable for the same
157
161
// reason.
158
- if stab. level . is_unstable ( ) {
162
+ if inherit_deprecation && stab. level . is_unstable ( ) {
159
163
self . index . stab_map . insert ( hir_id, stab) ;
160
164
}
161
165
}
@@ -187,7 +191,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
187
191
// Propagate unstability. This can happen even for non-staged-api crates in case
188
192
// -Zforce-unstable-if-unmarked is set.
189
193
if let Some ( stab) = self . parent_stab {
190
- if stab. level . is_unstable ( ) {
194
+ if inherit_deprecation && stab. level . is_unstable ( ) {
191
195
self . index . stab_map . insert ( hir_id, stab) ;
192
196
}
193
197
}
@@ -243,54 +247,68 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
243
247
}
244
248
hir:: ItemKind :: Struct ( ref sd, _) => {
245
249
if let Some ( ctor_hir_id) = sd. ctor_hir_id ( ) {
246
- self . annotate ( ctor_hir_id, & i. attrs , i. span , AnnotationKind :: Required , |_| { } )
250
+ self . annotate (
251
+ ctor_hir_id,
252
+ & i. attrs ,
253
+ i. span ,
254
+ AnnotationKind :: Required ,
255
+ true ,
256
+ |_| { } ,
257
+ )
247
258
}
248
259
}
249
260
_ => { }
250
261
}
251
262
252
- self . annotate ( i. hir_id , & i. attrs , i. span , kind, |v| intravisit:: walk_item ( v, i) ) ;
263
+ self . annotate ( i. hir_id , & i. attrs , i. span , kind, true , |v| intravisit:: walk_item ( v, i) ) ;
253
264
self . in_trait_impl = orig_in_trait_impl;
254
265
}
255
266
256
267
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
257
- self . annotate ( ti. hir_id , & ti. attrs , ti. span , AnnotationKind :: Required , |v| {
268
+ self . annotate ( ti. hir_id , & ti. attrs , ti. span , AnnotationKind :: Required , true , |v| {
258
269
intravisit:: walk_trait_item ( v, ti) ;
259
270
} ) ;
260
271
}
261
272
262
273
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
263
274
let kind =
264
275
if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
265
- self . annotate ( ii. hir_id , & ii. attrs , ii. span , kind, |v| {
276
+ self . annotate ( ii. hir_id , & ii. attrs , ii. span , kind, true , |v| {
266
277
intravisit:: walk_impl_item ( v, ii) ;
267
278
} ) ;
268
279
}
269
280
270
281
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
271
- self . annotate ( var. id , & var. attrs , var. span , AnnotationKind :: Required , |v| {
282
+ self . annotate ( var. id , & var. attrs , var. span , AnnotationKind :: Required , true , |v| {
272
283
if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
273
- v. annotate ( ctor_hir_id, & var. attrs , var. span , AnnotationKind :: Required , |_| { } ) ;
284
+ v. annotate (
285
+ ctor_hir_id,
286
+ & var. attrs ,
287
+ var. span ,
288
+ AnnotationKind :: Required ,
289
+ true ,
290
+ |_| { } ,
291
+ ) ;
274
292
}
275
293
276
294
intravisit:: walk_variant ( v, var, g, item_id)
277
295
} )
278
296
}
279
297
280
298
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
281
- self . annotate ( s. hir_id , & s. attrs , s. span , AnnotationKind :: Required , |v| {
299
+ self . annotate ( s. hir_id , & s. attrs , s. span , AnnotationKind :: Required , true , |v| {
282
300
intravisit:: walk_struct_field ( v, s) ;
283
301
} ) ;
284
302
}
285
303
286
304
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
287
- self . annotate ( i. hir_id , & i. attrs , i. span , AnnotationKind :: Required , |v| {
305
+ self . annotate ( i. hir_id , & i. attrs , i. span , AnnotationKind :: Required , true , |v| {
288
306
intravisit:: walk_foreign_item ( v, i) ;
289
307
} ) ;
290
308
}
291
309
292
310
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
293
- self . annotate ( md. hir_id , & md. attrs , md. span , AnnotationKind :: Required , |_| { } ) ;
311
+ self . annotate ( md. hir_id , & md. attrs , md. span , AnnotationKind :: Required , true , |_| { } ) ;
294
312
}
295
313
296
314
fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
@@ -302,7 +320,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
302
320
_ => AnnotationKind :: Prohibited ,
303
321
} ;
304
322
305
- self . annotate ( p. hir_id , & p. attrs , p. span , kind, |v| {
323
+ self . annotate ( p. hir_id , & p. attrs , p. span , kind, false , |v| {
306
324
intravisit:: walk_generic_param ( v, p) ;
307
325
} ) ;
308
326
}
@@ -442,6 +460,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
442
460
& krate. attrs ,
443
461
krate. span ,
444
462
AnnotationKind :: Required ,
463
+ true ,
445
464
|v| intravisit:: walk_crate ( v, krate) ,
446
465
) ;
447
466
}
0 commit comments