@@ -84,28 +84,28 @@ impl LintLevelSets {
84
84
) -> LevelAndSource {
85
85
let lint = LintId :: of ( lint) ;
86
86
let ( level, mut src) = self . raw_lint_id_level ( lint, idx, aux) ;
87
- let level = reveal_actual_level ( level, & mut src, sess, lint, |id| {
87
+ let ( level, lint_id ) = reveal_actual_level ( level, & mut src, sess, lint, |id| {
88
88
self . raw_lint_id_level ( id, idx, aux)
89
89
} ) ;
90
- LevelAndSource { level, src }
90
+ LevelAndSource { level, lint_id , src }
91
91
}
92
92
93
93
fn raw_lint_id_level (
94
94
& self ,
95
95
id : LintId ,
96
96
mut idx : LintStackIndex ,
97
97
aux : Option < & FxIndexMap < LintId , LevelAndSource > > ,
98
- ) -> ( Option < Level > , LintLevelSource ) {
98
+ ) -> ( Option < ( Level , Option < LintExpectationId > ) > , LintLevelSource ) {
99
99
if let Some ( specs) = aux
100
- && let Some ( & LevelAndSource { level, src } ) = specs. get ( & id)
100
+ && let Some ( & LevelAndSource { level, lint_id , src } ) = specs. get ( & id)
101
101
{
102
- return ( Some ( level) , src) ;
102
+ return ( Some ( ( level, lint_id ) ) , src) ;
103
103
}
104
104
105
105
loop {
106
106
let LintSet { ref specs, parent } = self . list [ idx] ;
107
- if let Some ( & LevelAndSource { level, src } ) = specs. get ( & id) {
108
- return ( Some ( level) , src) ;
107
+ if let Some ( & LevelAndSource { level, lint_id , src } ) = specs. get ( & id) {
108
+ return ( Some ( ( level, lint_id ) ) , src) ;
109
109
}
110
110
if idx == COMMAND_LINE {
111
111
return ( None , LintLevelSource :: Default ) ;
@@ -379,13 +379,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
379
379
fn visit_attribute ( & mut self , attribute : & ' tcx hir:: Attribute ) {
380
380
if matches ! (
381
381
Level :: from_attr( attribute) ,
382
- Some (
383
- Level :: Warn
384
- | Level :: Deny
385
- | Level :: Forbid
386
- | Level :: Expect ( ..)
387
- | Level :: ForceWarn ( ..) ,
388
- )
382
+ Some ( ( Level :: Warn | Level :: Deny | Level :: Forbid | Level :: Expect | Level :: ForceWarn , _) )
389
383
) {
390
384
let store = unerased_lint_store ( self . tcx . sess ) ;
391
385
// Lint attributes are always a metalist inside a
@@ -528,9 +522,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
528
522
for & ( ref lint_name, level) in & self . sess . opts . lint_opts {
529
523
// Checks the validity of lint names derived from the command line.
530
524
let ( tool_name, lint_name_only) = parse_lint_and_tool_name ( lint_name) ;
531
- if lint_name_only == crate :: WARNINGS . name_lower ( )
532
- && matches ! ( level, Level :: ForceWarn ( _) )
533
- {
525
+ if lint_name_only == crate :: WARNINGS . name_lower ( ) && matches ! ( level, Level :: ForceWarn ) {
534
526
self . sess
535
527
. dcx ( )
536
528
. emit_err ( UnsupportedGroup { lint_group : crate :: WARNINGS . name_lower ( ) } ) ;
@@ -573,7 +565,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
573
565
_ => { }
574
566
} ;
575
567
576
- let orig_level = level;
577
568
let lint_flag_val = Symbol :: intern ( lint_name) ;
578
569
579
570
let Ok ( ids) = self . store . find_lints ( lint_name) else {
@@ -582,15 +573,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
582
573
} ;
583
574
for id in ids {
584
575
// ForceWarn and Forbid cannot be overridden
585
- if let Some ( LevelAndSource { level : Level :: ForceWarn ( _ ) | Level :: Forbid , .. } ) =
576
+ if let Some ( LevelAndSource { level : Level :: ForceWarn | Level :: Forbid , .. } ) =
586
577
self . current_specs ( ) . get ( & id)
587
578
{
588
579
continue ;
589
580
}
590
581
591
582
if self . check_gated_lint ( id, DUMMY_SP , true ) {
592
- let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level ) ;
593
- self . insert ( id, LevelAndSource { level, src } ) ;
583
+ let src = LintLevelSource :: CommandLine ( lint_flag_val, level ) ;
584
+ self . insert ( id, LevelAndSource { level, lint_id : None , src } ) ;
594
585
}
595
586
}
596
587
}
@@ -599,8 +590,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
599
590
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
600
591
/// (e.g. if a forbid was already inserted on the same scope), then emits a
601
592
/// diagnostic with no change to `specs`.
602
- fn insert_spec ( & mut self , id : LintId , LevelAndSource { level, src } : LevelAndSource ) {
603
- let LevelAndSource { level : old_level, src : old_src } =
593
+ fn insert_spec ( & mut self , id : LintId , LevelAndSource { level, lint_id , src } : LevelAndSource ) {
594
+ let LevelAndSource { level : old_level, src : old_src, .. } =
604
595
self . provider . get_lint_level ( id. lint , self . sess ) ;
605
596
606
597
// Setting to a non-forbid level is an error if the lint previously had
@@ -673,24 +664,24 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
673
664
// The lint `unfulfilled_lint_expectations` can't be expected, as it would suppress itself.
674
665
// Handling expectations of this lint would add additional complexity with little to no
675
666
// benefit. The expect level for this lint will therefore be ignored.
676
- if let Level :: Expect ( _ ) = level
667
+ if let Level :: Expect = level
677
668
&& id == LintId :: of ( UNFULFILLED_LINT_EXPECTATIONS )
678
669
{
679
670
return ;
680
671
}
681
672
682
673
match ( old_level, level) {
683
674
// If the new level is an expectation store it in `ForceWarn`
684
- ( Level :: ForceWarn ( _) , Level :: Expect ( expectation_id) ) => self . insert (
675
+ ( Level :: ForceWarn , Level :: Expect ) => {
676
+ self . insert ( id, LevelAndSource { level : Level :: ForceWarn , lint_id, src : old_src } )
677
+ }
678
+ // Keep `ForceWarn` level but drop the expectation
679
+ ( Level :: ForceWarn , _) => self . insert (
685
680
id,
686
- LevelAndSource { level : Level :: ForceWarn ( Some ( expectation_id ) ) , src : old_src } ,
681
+ LevelAndSource { level : Level :: ForceWarn , lint_id : None , src : old_src } ,
687
682
) ,
688
- // Keep `ForceWarn` level but drop the expectation
689
- ( Level :: ForceWarn ( _) , _) => {
690
- self . insert ( id, LevelAndSource { level : Level :: ForceWarn ( None ) , src : old_src } )
691
- }
692
683
// Set the lint level as normal
693
- _ => self . insert ( id, LevelAndSource { level, src } ) ,
684
+ _ => self . insert ( id, LevelAndSource { level, lint_id , src } ) ,
694
685
} ;
695
686
}
696
687
@@ -705,7 +696,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
705
696
if attr. has_name ( sym:: automatically_derived) {
706
697
self . insert (
707
698
LintId :: of ( SINGLE_USE_LIFETIMES ) ,
708
- LevelAndSource { level : Level :: Allow , src : LintLevelSource :: Default } ,
699
+ LevelAndSource {
700
+ level : Level :: Allow ,
701
+ lint_id : None ,
702
+ src : LintLevelSource :: Default ,
703
+ } ,
709
704
) ;
710
705
continue ;
711
706
}
@@ -718,16 +713,20 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
718
713
{
719
714
self . insert (
720
715
LintId :: of ( MISSING_DOCS ) ,
721
- LevelAndSource { level : Level :: Allow , src : LintLevelSource :: Default } ,
716
+ LevelAndSource {
717
+ level : Level :: Allow ,
718
+ lint_id : None ,
719
+ src : LintLevelSource :: Default ,
720
+ } ,
722
721
) ;
723
722
continue ;
724
723
}
725
724
726
- let level = match Level :: from_attr ( attr) {
725
+ let ( level, lint_id ) = match Level :: from_attr ( attr) {
727
726
None => continue ,
728
727
// This is the only lint level with a `LintExpectationId` that can be created from
729
728
// an attribute.
730
- Some ( Level :: Expect ( unstable_id) ) if let Some ( hir_id) = source_hir_id => {
729
+ Some ( ( Level :: Expect , Some ( unstable_id) ) ) if let Some ( hir_id) = source_hir_id => {
731
730
let LintExpectationId :: Unstable { lint_index : None , attr_id : _ } = unstable_id
732
731
else {
733
732
bug ! ( "stable id Level::from_attr" )
@@ -739,9 +738,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
739
738
lint_index : None ,
740
739
} ;
741
740
742
- Level :: Expect ( stable_id)
741
+ ( Level :: Expect , Some ( stable_id) )
743
742
}
744
- Some ( lvl) => lvl,
743
+ Some ( ( lvl, id ) ) => ( lvl, id ) ,
745
744
} ;
746
745
747
746
let Some ( mut metas) = attr. meta_item_list ( ) else { continue } ;
@@ -789,13 +788,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
789
788
}
790
789
791
790
for ( lint_index, li) in metas. iter_mut ( ) . enumerate ( ) {
792
- let level = match level {
793
- Level :: Expect ( mut id) => {
794
- id. set_lint_index ( Some ( lint_index as u16 ) ) ;
795
- Level :: Expect ( id)
796
- }
797
- level => level,
798
- } ;
791
+ let mut lint_id = lint_id;
792
+ if let Some ( id) = & mut lint_id {
793
+ id. set_lint_index ( Some ( lint_index as u16 ) ) ;
794
+ }
799
795
800
796
let sp = li. span ( ) ;
801
797
let meta_item = match li {
@@ -927,7 +923,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
927
923
let src = LintLevelSource :: Node { name, span : sp, reason } ;
928
924
for & id in ids {
929
925
if self . check_gated_lint ( id, sp, false ) {
930
- self . insert_spec ( id, LevelAndSource { level, src } ) ;
926
+ self . insert_spec ( id, LevelAndSource { level, lint_id , src } ) ;
931
927
}
932
928
}
933
929
@@ -936,7 +932,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
936
932
// overriding the lint level but instead add an expectation that can't be
937
933
// fulfilled. The lint message will include an explanation, that the
938
934
// `unfulfilled_lint_expectations` lint can't be expected.
939
- if let Level :: Expect ( expect_id) = level {
935
+ if let ( Level :: Expect , Some ( expect_id) ) = ( level, lint_id ) {
940
936
// The `unfulfilled_lint_expectations` lint is not part of any lint
941
937
// groups. Therefore. we only need to check the slice if it contains a
942
938
// single lint.
@@ -958,7 +954,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
958
954
}
959
955
960
956
if self . lint_added_lints && !is_crate_node {
961
- for ( id, & LevelAndSource { level, ref src } ) in self . current_specs ( ) . iter ( ) {
957
+ for ( id, & LevelAndSource { level, ref src, .. } ) in self . current_specs ( ) . iter ( ) {
962
958
if !id. lint . crate_level_only {
963
959
continue ;
964
960
}
0 commit comments