@@ -37,6 +37,20 @@ enum AnnotationKind {
3737 Container ,
3838}
3939
40+ /// Inheriting deprecations Nested items causes duplicate warnings.
41+ /// Inheriting the deprecation of `Foo<T>` onto the parameter `T`, would cause a duplicate warnings.
42+ #[ derive( PartialEq , Copy , Clone ) ]
43+ enum InheritDeprecation {
44+ Yes ,
45+ No ,
46+ }
47+
48+ impl InheritDeprecation {
49+ fn yes ( & self ) -> bool {
50+ * self == InheritDeprecation :: Yes
51+ }
52+ }
53+
4054// A private tree-walker for producing an Index.
4155struct Annotator < ' a , ' tcx > {
4256 tcx : TyCtxt < ' tcx > ,
@@ -56,7 +70,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
5670 attrs : & [ Attribute ] ,
5771 item_sp : Span ,
5872 kind : AnnotationKind ,
59- inherit_deprecation : bool ,
73+ inherit_deprecation : InheritDeprecation ,
6074 visit_children : F ,
6175 ) where
6276 F : FnOnce ( & mut Self ) ,
@@ -81,7 +95,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
8195 let depr_entry = DeprecationEntry :: local ( depr. clone ( ) , hir_id) ;
8296 self . index . depr_map . insert ( hir_id, depr_entry) ;
8397 } else if let Some ( parent_depr) = self . parent_depr . clone ( ) {
84- if inherit_deprecation {
98+ if inherit_deprecation. yes ( ) {
8599 is_deprecated = true ;
86100 info ! ( "tagging child {:?} as deprecated from parent" , hir_id) ;
87101 self . index . depr_map . insert ( hir_id, parent_depr) ;
@@ -189,7 +203,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
189203 if stab. is_none ( ) {
190204 debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
191205 if let Some ( stab) = self . parent_stab {
192- if inherit_deprecation && stab. level . is_unstable ( ) {
206+ if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
193207 self . index . stab_map . insert ( hir_id, stab) ;
194208 }
195209 }
@@ -240,7 +254,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
240254 }
241255
242256 // returns true if an error occurred, used to suppress some spurious errors
243- fn forbid_staged_api_attrs ( & mut self , hir_id : HirId , attrs : & [ Attribute ] , inherit_deprecation : bool ) -> bool {
257+ fn forbid_staged_api_attrs ( & mut self , hir_id : HirId , attrs : & [ Attribute ] , inherit_deprecation : InheritDeprecation ) -> bool {
244258 // Emit errors for non-staged-api crates.
245259 let unstable_attrs = [
246260 sym:: unstable,
@@ -268,7 +282,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
268282 // Propagate unstability. This can happen even for non-staged-api crates in case
269283 // -Zforce-unstable-if-unmarked is set.
270284 if let Some ( stab) = self . parent_stab {
271- if inherit_deprecation && stab. level . is_unstable ( ) {
285+ if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
272286 self . index . stab_map . insert ( hir_id, stab) ;
273287 }
274288 }
@@ -309,63 +323,100 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
309323 & i. attrs ,
310324 i. span ,
311325 AnnotationKind :: Required ,
312- true ,
326+ InheritDeprecation :: Yes ,
313327 |_| { } ,
314328 )
315329 }
316330 }
317331 _ => { }
318332 }
319333
320- self . annotate ( i. hir_id , & i. attrs , i. span , kind, true , |v| intravisit:: walk_item ( v, i) ) ;
334+ self . annotate ( i. hir_id , & i. attrs , i. span , kind, InheritDeprecation :: Yes , |v| {
335+ intravisit:: walk_item ( v, i)
336+ } ) ;
321337 self . in_trait_impl = orig_in_trait_impl;
322338 }
323339
324340 fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
325- self . annotate ( ti. hir_id , & ti. attrs , ti. span , AnnotationKind :: Required , true , |v| {
326- intravisit:: walk_trait_item ( v, ti) ;
327- } ) ;
341+ self . annotate (
342+ ti. hir_id ,
343+ & ti. attrs ,
344+ ti. span ,
345+ AnnotationKind :: Required ,
346+ InheritDeprecation :: Yes ,
347+ |v| {
348+ intravisit:: walk_trait_item ( v, ti) ;
349+ } ,
350+ ) ;
328351 }
329352
330353 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
331354 let kind =
332355 if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
333- self . annotate ( ii. hir_id , & ii. attrs , ii. span , kind, true , |v| {
356+ self . annotate ( ii. hir_id , & ii. attrs , ii. span , kind, InheritDeprecation :: Yes , |v| {
334357 intravisit:: walk_impl_item ( v, ii) ;
335358 } ) ;
336359 }
337360
338361 fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
339- self . annotate ( var. id , & var. attrs , var. span , AnnotationKind :: Required , true , |v| {
340- if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
341- v. annotate (
342- ctor_hir_id,
343- & var. attrs ,
344- var. span ,
345- AnnotationKind :: Required ,
346- true ,
347- |_| { } ,
348- ) ;
349- }
362+ self . annotate (
363+ var. id ,
364+ & var. attrs ,
365+ var. span ,
366+ AnnotationKind :: Required ,
367+ InheritDeprecation :: Yes ,
368+ |v| {
369+ if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
370+ v. annotate (
371+ ctor_hir_id,
372+ & var. attrs ,
373+ var. span ,
374+ AnnotationKind :: Required ,
375+ InheritDeprecation :: Yes ,
376+ |_| { } ,
377+ ) ;
378+ }
350379
351- intravisit:: walk_variant ( v, var, g, item_id)
352- } )
380+ intravisit:: walk_variant ( v, var, g, item_id)
381+ } ,
382+ )
353383 }
354384
355385 fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
356- self . annotate ( s. hir_id , & s. attrs , s. span , AnnotationKind :: Required , true , |v| {
357- intravisit:: walk_struct_field ( v, s) ;
358- } ) ;
386+ self . annotate (
387+ s. hir_id ,
388+ & s. attrs ,
389+ s. span ,
390+ AnnotationKind :: Required ,
391+ InheritDeprecation :: Yes ,
392+ |v| {
393+ intravisit:: walk_struct_field ( v, s) ;
394+ } ,
395+ ) ;
359396 }
360397
361398 fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
362- self . annotate ( i. hir_id , & i. attrs , i. span , AnnotationKind :: Required , true , |v| {
363- intravisit:: walk_foreign_item ( v, i) ;
364- } ) ;
399+ self . annotate (
400+ i. hir_id ,
401+ & i. attrs ,
402+ i. span ,
403+ AnnotationKind :: Required ,
404+ InheritDeprecation :: Yes ,
405+ |v| {
406+ intravisit:: walk_foreign_item ( v, i) ;
407+ } ,
408+ ) ;
365409 }
366410
367411 fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
368- self . annotate ( md. hir_id , & md. attrs , md. span , AnnotationKind :: Required , true , |_| { } ) ;
412+ self . annotate (
413+ md. hir_id ,
414+ & md. attrs ,
415+ md. span ,
416+ AnnotationKind :: Required ,
417+ InheritDeprecation :: Yes ,
418+ |_| { } ,
419+ ) ;
369420 }
370421
371422 fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
@@ -377,7 +428,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
377428 _ => AnnotationKind :: Prohibited ,
378429 } ;
379430
380- self . annotate ( p. hir_id , & p. attrs , p. span , kind, false , |v| {
431+ self . annotate ( p. hir_id , & p. attrs , p. span , kind, InheritDeprecation :: No , |v| {
381432 intravisit:: walk_generic_param ( v, p) ;
382433 } ) ;
383434 }
@@ -519,7 +570,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
519570 & krate. item . attrs ,
520571 krate. item . span ,
521572 AnnotationKind :: Required ,
522- true ,
573+ InheritDeprecation :: Yes ,
523574 |v| intravisit:: walk_crate ( v, krate) ,
524575 ) ;
525576 }
0 commit comments