@@ -129,7 +129,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> UnordSet<LintId> {
129129 let level_spec =
130130 root_map. lint_level_spec_at_node ( tcx, LintId :: of ( lint) , hir:: CRATE_HIR_ID ) ;
131131 // Only include lints that are allowed at crate root or by default.
132- matches ! ( level_spec. level , Level :: Allow )
132+ level_spec. is_allow ( )
133133 || ( matches ! ( level_spec. src, LintLevelSource :: Default )
134134 && lint. default_level ( tcx. sess . edition ( ) ) == Level :: Allow )
135135 } )
@@ -142,7 +142,7 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> UnordSet<LintId> {
142142 // All lints that appear with a non-allow level must be run.
143143 for ( _, specs) in map. specs . iter ( ) {
144144 for ( lint, level_spec) in specs. iter ( ) {
145- if !matches ! ( level_spec. level , Level :: Allow ) {
145+ if !level_spec. is_allow ( ) {
146146 dont_need_to_run. remove ( lint) ;
147147 }
148148 }
@@ -520,15 +520,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
520520 } ;
521521 for & id in ids {
522522 // ForceWarn and Forbid cannot be overridden
523- if let Some ( LevelSpec { level : Level :: ForceWarn | Level :: Forbid , .. } ) =
524- self . current_specs ( ) . get ( & id )
523+ if let Some ( level_spec ) = self . current_specs ( ) . get ( & id )
524+ && matches ! ( level_spec . level ( ) , Level :: ForceWarn | Level :: Forbid )
525525 {
526526 continue ;
527527 }
528528
529529 if self . check_gated_lint ( id, DUMMY_SP , true ) {
530530 let src = LintLevelSource :: CommandLine ( lint_flag_val, level) ;
531- self . insert ( id, LevelSpec { level, lint_id : None , src } ) ;
531+ self . insert ( id, LevelSpec :: new ( level, None , src) ) ;
532532 }
533533 }
534534 }
@@ -537,9 +537,14 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
537537 /// Attempts to insert the `id` to `LevelSpec` map entry. If unsuccessful
538538 /// (e.g. if a forbid was already inserted on the same scope), then emits a
539539 /// diagnostic with no change to `specs`.
540- fn insert_spec ( & mut self , id : LintId , LevelSpec { level, lint_id, src } : LevelSpec ) {
541- let LevelSpec { level : old_level, src : old_src, .. } =
542- self . provider . get_lint_level_spec ( id. lint , self . sess ) ;
540+ fn insert_spec ( & mut self , id : LintId , level_spec : LevelSpec ) {
541+ let level = level_spec. level ( ) ;
542+ let lint_id = level_spec. lint_id ( ) ;
543+ let src = level_spec. src ;
544+
545+ let old_level_spec = self . provider . get_lint_level_spec ( id. lint , self . sess ) ;
546+ let old_level = old_level_spec. level ( ) ;
547+ let old_src = old_level_spec. src ;
543548
544549 // Setting to a non-forbid level is an error if the lint previously had
545550 // a forbid level. Note that this is not necessarily true even with a
@@ -622,14 +627,14 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
622627 match ( old_level, level) {
623628 // If the new level is an expectation store it in `ForceWarn`
624629 ( Level :: ForceWarn , Level :: Expect ) => {
625- self . insert ( id, LevelSpec { level : Level :: ForceWarn , lint_id, src : old_src } )
630+ self . insert ( id, LevelSpec :: new ( Level :: ForceWarn , lint_id, old_src) )
626631 }
627632 // Keep `ForceWarn` level but drop the expectation
628633 ( Level :: ForceWarn , _) => {
629- self . insert ( id, LevelSpec { level : Level :: ForceWarn , lint_id : None , src : old_src } )
634+ self . insert ( id, LevelSpec :: new ( Level :: ForceWarn , None , old_src) )
630635 }
631636 // Set the lint level as normal
632- _ => self . insert ( id, LevelSpec { level, lint_id, src } ) ,
637+ _ => self . insert ( id, LevelSpec :: new ( level, lint_id, src) ) ,
633638 } ;
634639 }
635640
@@ -644,7 +649,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
644649 if attr. is_automatically_derived_attr ( ) {
645650 self . insert (
646651 LintId :: of ( SINGLE_USE_LIFETIMES ) ,
647- LevelSpec { level : Level :: Allow , lint_id : None , src : LintLevelSource :: Default } ,
652+ LevelSpec :: new ( Level :: Allow , None , LintLevelSource :: Default ) ,
648653 ) ;
649654 continue ;
650655 }
@@ -653,7 +658,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
653658 if attr. is_doc_hidden ( ) {
654659 self . insert (
655660 LintId :: of ( MISSING_DOCS ) ,
656- LevelSpec { level : Level :: Allow , lint_id : None , src : LintLevelSource :: Default } ,
661+ LevelSpec :: new ( Level :: Allow , None , LintLevelSource :: Default ) ,
657662 ) ;
658663 continue ;
659664 }
@@ -866,7 +871,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
866871 let src = LintLevelSource :: Node { name, span : sp, reason } ;
867872 for & id in ids {
868873 if self . check_gated_lint ( id, sp, false ) {
869- self . insert_spec ( id, LevelSpec { level, lint_id, src } ) ;
874+ self . insert_spec ( id, LevelSpec :: new ( level, lint_id, src) ) ;
870875 }
871876 }
872877
@@ -897,20 +902,24 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
897902 }
898903
899904 if self . lint_added_lints && !is_crate_node {
900- for ( id, & LevelSpec { level , ref src , .. } ) in self . current_specs ( ) . iter ( ) {
905+ for ( id, level_spec ) in self . current_specs ( ) . iter ( ) {
901906 if !id. lint . crate_level_only {
902907 continue ;
903908 }
904909
905- let LintLevelSource :: Node { name : lint_attr_name, span : lint_attr_span, .. } = * src
910+ let LintLevelSource :: Node { name : lint_attr_name, span : lint_attr_span, .. } =
911+ level_spec. src
906912 else {
907913 continue ;
908914 } ;
909915
910916 self . emit_span_lint (
911917 UNUSED_ATTRIBUTES ,
912918 lint_attr_span. into ( ) ,
913- IgnoredUnlessCrateSpecified { level : level. as_str ( ) , name : lint_attr_name } ,
919+ IgnoredUnlessCrateSpecified {
920+ level : level_spec. level ( ) . as_str ( ) ,
921+ name : lint_attr_name,
922+ } ,
914923 ) ;
915924 // don't set a separate error for every lint in the group
916925 break ;
0 commit comments