@@ -97,7 +97,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
97
97
fn annotate < F > (
98
98
& mut self ,
99
99
hir_id : HirId ,
100
- item_sp : Span ,
101
100
kind : AnnotationKind ,
102
101
inherit_deprecation : InheritDeprecation ,
103
102
inherit_const_stability : InheritConstStability ,
@@ -142,16 +141,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
142
141
}
143
142
}
144
143
145
- if self . tcx . features ( ) . staged_api {
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 ( ) ;
153
- }
154
- } else {
144
+ if !self . tcx . features ( ) . staged_api {
155
145
self . recurse_with_stability_attrs (
156
146
depr. map ( |( d, _) | DeprecationEntry :: local ( d, hir_id) ) ,
157
147
None ,
@@ -161,6 +151,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
161
151
return ;
162
152
}
163
153
154
+ let item_sp = self . tcx . hir ( ) . span_with_body ( hir_id) ;
155
+ if let Some ( a) = attrs. iter ( ) . find ( |a| self . tcx . sess . check_name ( a, sym:: deprecated) ) {
156
+ self . tcx
157
+ . sess
158
+ . struct_span_err ( a. span , "`#[deprecated]` cannot be used in staged API" )
159
+ . span_label ( a. span , "use `#[rustc_deprecated]` instead" )
160
+ . span_label ( item_sp, "" )
161
+ . emit ( ) ;
162
+ }
163
+
164
164
let ( stab, const_stab) = attr:: find_stability ( & self . tcx . sess , attrs, item_sp) ;
165
165
166
166
let const_stab = const_stab. map ( |( const_stab, _) | {
@@ -385,7 +385,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
385
385
if let Some ( ctor_hir_id) = sd. ctor_hir_id ( ) {
386
386
self . annotate (
387
387
ctor_hir_id,
388
- i. span ,
389
388
AnnotationKind :: Required ,
390
389
InheritDeprecation :: Yes ,
391
390
InheritConstStability :: No ,
@@ -399,7 +398,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
399
398
400
399
self . annotate (
401
400
i. hir_id ( ) ,
402
- i. span ,
403
401
kind,
404
402
InheritDeprecation :: Yes ,
405
403
const_stab_inherit,
@@ -412,7 +410,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
412
410
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
413
411
self . annotate (
414
412
ti. hir_id ( ) ,
415
- ti. span ,
416
413
AnnotationKind :: Required ,
417
414
InheritDeprecation :: Yes ,
418
415
InheritConstStability :: No ,
@@ -428,7 +425,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
428
425
if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
429
426
self . annotate (
430
427
ii. hir_id ( ) ,
431
- ii. span ,
432
428
kind,
433
429
InheritDeprecation :: Yes ,
434
430
InheritConstStability :: No ,
@@ -440,10 +436,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
440
436
}
441
437
442
438
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
443
- let var_span = self . tcx . hir ( ) . span ( var. id ) ;
444
439
self . annotate (
445
440
var. id ,
446
- var_span,
447
441
AnnotationKind :: Required ,
448
442
InheritDeprecation :: Yes ,
449
443
InheritConstStability :: No ,
@@ -452,7 +446,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
452
446
if let Some ( ctor_hir_id) = var. data . ctor_hir_id ( ) {
453
447
v. annotate (
454
448
ctor_hir_id,
455
- var_span,
456
449
AnnotationKind :: Required ,
457
450
InheritDeprecation :: Yes ,
458
451
InheritConstStability :: No ,
@@ -467,10 +460,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
467
460
}
468
461
469
462
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
470
- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
471
463
self . annotate (
472
464
s. hir_id ,
473
- span,
474
465
AnnotationKind :: Required ,
475
466
InheritDeprecation :: Yes ,
476
467
InheritConstStability :: No ,
@@ -484,7 +475,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
484
475
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
485
476
self . annotate (
486
477
i. hir_id ( ) ,
487
- i. span ,
488
478
AnnotationKind :: Required ,
489
479
InheritDeprecation :: Yes ,
490
480
InheritConstStability :: No ,
@@ -496,10 +486,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
496
486
}
497
487
498
488
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
499
- let span = self . tcx . hir ( ) . span ( md. hir_id ( ) ) ;
500
489
self . annotate (
501
490
md. hir_id ( ) ,
502
- span,
503
491
AnnotationKind :: Required ,
504
492
InheritDeprecation :: Yes ,
505
493
InheritConstStability :: No ,
@@ -517,10 +505,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
517
505
_ => AnnotationKind :: Prohibited ,
518
506
} ;
519
507
520
- let span = self . tcx . hir ( ) . span ( p. hir_id ) ;
521
508
self . annotate (
522
509
p. hir_id ,
523
- span,
524
510
kind,
525
511
InheritDeprecation :: No ,
526
512
InheritConstStability :: No ,
@@ -538,23 +524,25 @@ struct MissingStabilityAnnotations<'tcx> {
538
524
}
539
525
540
526
impl < ' tcx > MissingStabilityAnnotations < ' tcx > {
541
- fn check_missing_stability ( & self , hir_id : HirId , span : Span ) {
527
+ fn check_missing_stability ( & self , hir_id : HirId ) {
542
528
let stab = self . tcx . stability ( ) . local_stability ( hir_id) ;
543
529
let is_error =
544
530
!self . tcx . sess . opts . test && stab. is_none ( ) && self . access_levels . is_reachable ( hir_id) ;
545
531
if is_error {
546
532
let def_id = self . tcx . hir ( ) . local_def_id ( hir_id) ;
547
533
let descr = self . tcx . def_kind ( def_id) . descr ( def_id. to_def_id ( ) ) ;
534
+ let span = self . tcx . hir ( ) . span_with_body ( hir_id) ;
548
535
self . tcx . sess . span_err ( span, & format ! ( "{} has missing stability attribute" , descr) ) ;
549
536
}
550
537
}
551
538
552
- fn check_missing_const_stability ( & self , hir_id : HirId , span : Span ) {
539
+ fn check_missing_const_stability ( & self , hir_id : HirId ) {
553
540
let stab_map = self . tcx . stability ( ) ;
554
541
let stab = stab_map. local_stability ( hir_id) ;
555
542
if stab. map_or ( false , |stab| stab. level . is_stable ( ) ) {
556
543
let const_stab = stab_map. local_const_stability ( hir_id) ;
557
544
if const_stab. is_none ( ) {
545
+ let span = self . tcx . hir ( ) . span_with_body ( hir_id) ;
558
546
self . tcx . sess . span_err (
559
547
span,
560
548
"`#[stable]` const functions must also be either \
@@ -582,53 +570,50 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
582
570
hir:: ItemKind :: Impl ( hir:: Impl { of_trait: None , .. } )
583
571
| hir:: ItemKind :: ForeignMod { .. }
584
572
) {
585
- self . check_missing_stability ( i. hir_id ( ) , i . span ) ;
573
+ self . check_missing_stability ( i. hir_id ( ) ) ;
586
574
}
587
575
588
576
// Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
589
577
// `rustc_const_stable`.
590
578
if self . tcx . features ( ) . staged_api
591
579
&& matches ! ( & i. kind, hir:: ItemKind :: Fn ( sig, ..) if sig. header. is_const( ) )
592
580
{
593
- self . check_missing_const_stability ( i. hir_id ( ) , i . span ) ;
581
+ self . check_missing_const_stability ( i. hir_id ( ) ) ;
594
582
}
595
583
596
584
intravisit:: walk_item ( self , i)
597
585
}
598
586
599
587
fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
600
- self . check_missing_stability ( ti. hir_id ( ) , ti . span ) ;
588
+ self . check_missing_stability ( ti. hir_id ( ) ) ;
601
589
intravisit:: walk_trait_item ( self , ti) ;
602
590
}
603
591
604
592
fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
605
593
let impl_def_id = self . tcx . hir ( ) . local_def_id ( self . tcx . hir ( ) . get_parent_item ( ii. hir_id ( ) ) ) ;
606
594
if self . tcx . impl_trait_ref ( impl_def_id) . is_none ( ) {
607
- self . check_missing_stability ( ii. hir_id ( ) , ii . span ) ;
595
+ self . check_missing_stability ( ii. hir_id ( ) ) ;
608
596
}
609
597
intravisit:: walk_impl_item ( self , ii) ;
610
598
}
611
599
612
600
fn visit_variant ( & mut self , var : & ' tcx Variant < ' tcx > , g : & ' tcx Generics < ' tcx > , item_id : HirId ) {
613
- let span = self . tcx . hir ( ) . span ( var. id ) ;
614
- self . check_missing_stability ( var. id , span) ;
601
+ self . check_missing_stability ( var. id ) ;
615
602
intravisit:: walk_variant ( self , var, g, item_id) ;
616
603
}
617
604
618
605
fn visit_struct_field ( & mut self , s : & ' tcx StructField < ' tcx > ) {
619
- let span = self . tcx . hir ( ) . span ( s. hir_id ) ;
620
- self . check_missing_stability ( s. hir_id , span) ;
606
+ self . check_missing_stability ( s. hir_id ) ;
621
607
intravisit:: walk_struct_field ( self , s) ;
622
608
}
623
609
624
610
fn visit_foreign_item ( & mut self , i : & ' tcx hir:: ForeignItem < ' tcx > ) {
625
- self . check_missing_stability ( i. hir_id ( ) , i . span ) ;
611
+ self . check_missing_stability ( i. hir_id ( ) ) ;
626
612
intravisit:: walk_foreign_item ( self , i) ;
627
613
}
628
614
629
615
fn visit_macro_def ( & mut self , md : & ' tcx hir:: MacroDef < ' tcx > ) {
630
- let span = self . tcx . hir ( ) . span ( md. hir_id ( ) ) ;
631
- self . check_missing_stability ( md. hir_id ( ) , span) ;
616
+ self . check_missing_stability ( md. hir_id ( ) ) ;
632
617
}
633
618
634
619
// Note that we don't need to `check_missing_stability` for default generic parameters,
@@ -693,7 +678,6 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
693
678
694
679
annotator. annotate (
695
680
hir:: CRATE_HIR_ID ,
696
- tcx. hir ( ) . span ( hir:: CRATE_HIR_ID ) ,
697
681
AnnotationKind :: Required ,
698
682
InheritDeprecation :: Yes ,
699
683
InheritConstStability :: No ,
@@ -892,7 +876,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
892
876
if tcx. stability ( ) . staged_api [ & LOCAL_CRATE ] {
893
877
let krate = tcx. hir ( ) . krate ( ) ;
894
878
let mut missing = MissingStabilityAnnotations { tcx, access_levels } ;
895
- missing. check_missing_stability ( hir:: CRATE_HIR_ID , tcx . hir ( ) . span ( hir :: CRATE_HIR_ID ) ) ;
879
+ missing. check_missing_stability ( hir:: CRATE_HIR_ID ) ;
896
880
intravisit:: walk_crate ( & mut missing, krate) ;
897
881
krate. visit_all_item_likes ( & mut missing. as_deep_visitor ( ) ) ;
898
882
}
0 commit comments