@@ -68,6 +68,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
6868 attrs : & [ Attribute ] ,
6969 item_sp : Span ,
7070 kind : AnnotationKind ,
71+ inherit_deprecation : bool ,
7172 visit_children : F ,
7273 ) where
7374 F : FnOnce ( & mut Self ) ,
@@ -102,8 +103,11 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
102103 // If parent is deprecated and we're not, inherit this by merging
103104 // deprecated_since and its reason.
104105 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 ( )
107111 }
108112 }
109113
@@ -155,7 +159,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
155159 // Instability is inherited from the parent: if something is unstable,
156160 // everything inside it should also be considered unstable for the same
157161 // reason.
158- if stab. level . is_unstable ( ) {
162+ if inherit_deprecation && stab. level . is_unstable ( ) {
159163 self . index . stab_map . insert ( hir_id, stab) ;
160164 }
161165 }
@@ -187,7 +191,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
187191 // Propagate unstability. This can happen even for non-staged-api crates in case
188192 // -Zforce-unstable-if-unmarked is set.
189193 if let Some ( stab) = self . parent_stab {
190- if stab. level . is_unstable ( ) {
194+ if inherit_deprecation && stab. level . is_unstable ( ) {
191195 self . index . stab_map . insert ( hir_id, stab) ;
192196 }
193197 }
@@ -243,54 +247,68 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
243247 }
244248 hir:: ItemKind :: Struct ( ref sd, _) => {
245249 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+ )
247258 }
248259 }
249260 _ => { }
250261 }
251262
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) ) ;
253264 self . in_trait_impl = orig_in_trait_impl;
254265 }
255266
256267 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| {
258269 intravisit:: walk_trait_item ( v, ti) ;
259270 } ) ;
260271 }
261272
262273 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
263274 let kind =
264275 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| {
266277 intravisit:: walk_impl_item ( v, ii) ;
267278 } ) ;
268279 }
269280
270281 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| {
272283 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+ ) ;
274292 }
275293
276294 intravisit:: walk_variant ( v, var, g, item_id)
277295 } )
278296 }
279297
280298 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| {
282300 intravisit:: walk_struct_field ( v, s) ;
283301 } ) ;
284302 }
285303
286304 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| {
288306 intravisit:: walk_foreign_item ( v, i) ;
289307 } ) ;
290308 }
291309
292310 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 , |_| { } ) ;
294312 }
295313
296314 fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
@@ -302,7 +320,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
302320 _ => AnnotationKind :: Prohibited ,
303321 } ;
304322
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| {
306324 intravisit:: walk_generic_param ( v, p) ;
307325 } ) ;
308326 }
@@ -442,6 +460,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
442460 & krate. attrs ,
443461 krate. span ,
444462 AnnotationKind :: Required ,
463+ true ,
445464 |v| intravisit:: walk_crate ( v, krate) ,
446465 ) ;
447466 }
0 commit comments