@@ -37,6 +37,20 @@ enum AnnotationKind {
37
37
Container ,
38
38
}
39
39
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
+
40
54
// A private tree-walker for producing an Index.
41
55
struct Annotator < ' a , ' tcx > {
42
56
tcx : TyCtxt < ' tcx > ,
@@ -56,7 +70,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
56
70
attrs : & [ Attribute ] ,
57
71
item_sp : Span ,
58
72
kind : AnnotationKind ,
59
- inherit_deprecation : bool ,
73
+ inherit_deprecation : InheritDeprecation ,
60
74
visit_children : F ,
61
75
) where
62
76
F : FnOnce ( & mut Self ) ,
@@ -81,7 +95,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
81
95
let depr_entry = DeprecationEntry :: local ( depr. clone ( ) , hir_id) ;
82
96
self . index . depr_map . insert ( hir_id, depr_entry) ;
83
97
} else if let Some ( parent_depr) = self . parent_depr . clone ( ) {
84
- if inherit_deprecation {
98
+ if inherit_deprecation. yes ( ) {
85
99
is_deprecated = true ;
86
100
info ! ( "tagging child {:?} as deprecated from parent" , hir_id) ;
87
101
self . index . depr_map . insert ( hir_id, parent_depr) ;
@@ -189,7 +203,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
189
203
if stab. is_none ( ) {
190
204
debug ! ( "annotate: stab not found, parent = {:?}" , self . parent_stab) ;
191
205
if let Some ( stab) = self . parent_stab {
192
- if inherit_deprecation && stab. level . is_unstable ( ) {
206
+ if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
193
207
self . index . stab_map . insert ( hir_id, stab) ;
194
208
}
195
209
}
@@ -240,7 +254,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
240
254
}
241
255
242
256
// 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 {
244
258
// Emit errors for non-staged-api crates.
245
259
let unstable_attrs = [
246
260
sym:: unstable,
@@ -268,7 +282,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
268
282
// Propagate unstability. This can happen even for non-staged-api crates in case
269
283
// -Zforce-unstable-if-unmarked is set.
270
284
if let Some ( stab) = self . parent_stab {
271
- if inherit_deprecation && stab. level . is_unstable ( ) {
285
+ if inherit_deprecation. yes ( ) && stab. level . is_unstable ( ) {
272
286
self . index . stab_map . insert ( hir_id, stab) ;
273
287
}
274
288
}
@@ -309,63 +323,100 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
309
323
& i. attrs ,
310
324
i. span ,
311
325
AnnotationKind :: Required ,
312
- true ,
326
+ InheritDeprecation :: Yes ,
313
327
|_| { } ,
314
328
)
315
329
}
316
330
}
317
331
_ => { }
318
332
}
319
333
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
+ } ) ;
321
337
self . in_trait_impl = orig_in_trait_impl;
322
338
}
323
339
324
340
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
+ ) ;
328
351
}
329
352
330
353
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
331
354
let kind =
332
355
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| {
334
357
intravisit:: walk_impl_item ( v, ii) ;
335
358
} ) ;
336
359
}
337
360
338
361
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
+ }
350
379
351
- intravisit:: walk_variant ( v, var, g, item_id)
352
- } )
380
+ intravisit:: walk_variant ( v, var, g, item_id)
381
+ } ,
382
+ )
353
383
}
354
384
355
385
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
+ ) ;
359
396
}
360
397
361
398
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
+ ) ;
365
409
}
366
410
367
411
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
+ ) ;
369
420
}
370
421
371
422
fn visit_generic_param ( & mut self , p : & ' tcx hir:: GenericParam < ' tcx > ) {
@@ -377,7 +428,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
377
428
_ => AnnotationKind :: Prohibited ,
378
429
} ;
379
430
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| {
381
432
intravisit:: walk_generic_param ( v, p) ;
382
433
} ) ;
383
434
}
@@ -519,7 +570,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
519
570
& krate. item . attrs ,
520
571
krate. item . span ,
521
572
AnnotationKind :: Required ,
522
- true ,
573
+ InheritDeprecation :: Yes ,
523
574
|v| intravisit:: walk_crate ( v, krate) ,
524
575
) ;
525
576
}
0 commit comments