@@ -84,28 +84,28 @@ impl LintLevelSets {
8484 ) -> LevelAndSource {
8585 let lint = LintId :: of ( lint) ;
8686 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| {
8888 self . raw_lint_id_level ( id, idx, aux)
8989 } ) ;
90- LevelAndSource { level, src }
90+ LevelAndSource { level, lint_id , src }
9191 }
9292
9393 fn raw_lint_id_level (
9494 & self ,
9595 id : LintId ,
9696 mut idx : LintStackIndex ,
9797 aux : Option < & FxIndexMap < LintId , LevelAndSource > > ,
98- ) -> ( Option < Level > , LintLevelSource ) {
98+ ) -> ( Option < ( Level , Option < LintExpectationId > ) > , LintLevelSource ) {
9999 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)
101101 {
102- return ( Some ( level) , src) ;
102+ return ( Some ( ( level, lint_id ) ) , src) ;
103103 }
104104
105105 loop {
106106 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) ;
109109 }
110110 if idx == COMMAND_LINE {
111111 return ( None , LintLevelSource :: Default ) ;
@@ -379,13 +379,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
379379 fn visit_attribute ( & mut self , attribute : & ' tcx hir:: Attribute ) {
380380 if matches ! (
381381 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 , _) )
389383 ) {
390384 let store = unerased_lint_store ( self . tcx . sess ) ;
391385 // Lint attributes are always a metalist inside a
@@ -528,9 +522,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
528522 for & ( ref lint_name, level) in & self . sess . opts . lint_opts {
529523 // Checks the validity of lint names derived from the command line.
530524 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 ) {
534526 self . sess
535527 . dcx ( )
536528 . emit_err ( UnsupportedGroup { lint_group : crate :: WARNINGS . name_lower ( ) } ) ;
@@ -573,7 +565,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
573565 _ => { }
574566 } ;
575567
576- let orig_level = level;
577568 let lint_flag_val = Symbol :: intern ( lint_name) ;
578569
579570 let Ok ( ids) = self . store . find_lints ( lint_name) else {
@@ -582,15 +573,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
582573 } ;
583574 for id in ids {
584575 // 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 , .. } ) =
586577 self . current_specs ( ) . get ( & id)
587578 {
588579 continue ;
589580 }
590581
591582 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 } ) ;
594585 }
595586 }
596587 }
@@ -599,8 +590,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
599590 /// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
600591 /// (e.g. if a forbid was already inserted on the same scope), then emits a
601592 /// 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, .. } =
604595 self . provider . get_lint_level ( id. lint , self . sess ) ;
605596
606597 // 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> {
673664 // The lint `unfulfilled_lint_expectations` can't be expected, as it would suppress itself.
674665 // Handling expectations of this lint would add additional complexity with little to no
675666 // benefit. The expect level for this lint will therefore be ignored.
676- if let Level :: Expect ( _ ) = level
667+ if let Level :: Expect = level
677668 && id == LintId :: of ( UNFULFILLED_LINT_EXPECTATIONS )
678669 {
679670 return ;
680671 }
681672
682673 match ( old_level, level) {
683674 // 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 (
685680 id,
686- LevelAndSource { level : Level :: ForceWarn ( Some ( expectation_id ) ) , src : old_src } ,
681+ LevelAndSource { level : Level :: ForceWarn , lint_id : None , src : old_src } ,
687682 ) ,
688- // Keep `ForceWarn` level but drop the expectation
689- ( Level :: ForceWarn ( _) , _) => {
690- self . insert ( id, LevelAndSource { level : Level :: ForceWarn ( None ) , src : old_src } )
691- }
692683 // Set the lint level as normal
693- _ => self . insert ( id, LevelAndSource { level, src } ) ,
684+ _ => self . insert ( id, LevelAndSource { level, lint_id , src } ) ,
694685 } ;
695686 }
696687
@@ -705,7 +696,11 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
705696 if attr. has_name ( sym:: automatically_derived) {
706697 self . insert (
707698 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+ } ,
709704 ) ;
710705 continue ;
711706 }
@@ -718,16 +713,20 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
718713 {
719714 self . insert (
720715 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+ } ,
722721 ) ;
723722 continue ;
724723 }
725724
726- let level = match Level :: from_attr ( attr) {
725+ let ( level, lint_id ) = match Level :: from_attr ( attr) {
727726 None => continue ,
728727 // This is the only lint level with a `LintExpectationId` that can be created from
729728 // 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 => {
731730 let LintExpectationId :: Unstable { lint_index : None , attr_id : _ } = unstable_id
732731 else {
733732 bug ! ( "stable id Level::from_attr" )
@@ -739,9 +738,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
739738 lint_index : None ,
740739 } ;
741740
742- Level :: Expect ( stable_id)
741+ ( Level :: Expect , Some ( stable_id) )
743742 }
744- Some ( lvl) => lvl,
743+ Some ( ( lvl, id ) ) => ( lvl, id ) ,
745744 } ;
746745
747746 let Some ( mut metas) = attr. meta_item_list ( ) else { continue } ;
@@ -789,13 +788,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
789788 }
790789
791790 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+ }
799795
800796 let sp = li. span ( ) ;
801797 let meta_item = match li {
@@ -927,7 +923,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
927923 let src = LintLevelSource :: Node { name, span : sp, reason } ;
928924 for & id in ids {
929925 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 } ) ;
931927 }
932928 }
933929
@@ -936,7 +932,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
936932 // overriding the lint level but instead add an expectation that can't be
937933 // fulfilled. The lint message will include an explanation, that the
938934 // `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 ) {
940936 // The `unfulfilled_lint_expectations` lint is not part of any lint
941937 // groups. Therefore. we only need to check the slice if it contains a
942938 // single lint.
@@ -958,7 +954,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
958954 }
959955
960956 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 ( ) {
962958 if !id. lint . crate_level_only {
963959 continue ;
964960 }
0 commit comments