@@ -4,8 +4,8 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
44use rustc_data_structures:: unord:: UnordSet ;
55use rustc_errors:: { Diag , LintDiagnostic , MultiSpan } ;
66use rustc_feature:: { Features , GateIssue } ;
7- use rustc_hir:: HirId ;
87use rustc_hir:: intravisit:: { self , Visitor } ;
8+ use rustc_hir:: { HirId , OwnerId } ;
99use rustc_index:: IndexVec ;
1010use rustc_middle:: bug;
1111use rustc_middle:: hir:: nested_filter;
@@ -116,8 +116,29 @@ impl LintLevelSets {
116116 }
117117}
118118
119+ fn lints_that_will_run_for_id ( tcx : TyCtxt < ' _ > , key : OwnerId ) -> Vec < LintId > {
120+ let shallow_lint_level = tcx. shallow_lint_levels_on ( key) ;
121+
122+ let mut needs_to_run = Vec :: new ( ) ;
123+
124+ for ( _, specs) in shallow_lint_level. specs . iter ( ) {
125+ for ( lint, level_and_source) in specs. iter ( ) {
126+ if !matches ! ( level_and_source. level, Level :: Allow ) {
127+ needs_to_run. push ( * lint)
128+ }
129+ }
130+ }
131+
132+ needs_to_run
133+ }
134+
119135fn lints_that_dont_need_to_run ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> UnordSet < LintId > {
120136 let store = unerased_lint_store ( & tcx. sess ) ;
137+
138+ if tcx. sess . opts . lint_cap . is_some_and ( |level| level == Level :: Allow ) {
139+ return UnordSet :: from_iter ( store. get_lints ( ) . into_iter ( ) . map ( |lint| LintId :: of ( * lint) ) ) ;
140+ }
141+
121142 let root_map = tcx. shallow_lint_levels_on ( hir:: CRATE_OWNER_ID ) ;
122143
123144 let mut dont_need_to_run: FxHashSet < LintId > = store
@@ -141,15 +162,9 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> UnordSet<LintId> {
141162 . collect ( ) ;
142163
143164 for owner in tcx. hir_crate_items ( ( ) ) . owners ( ) {
144- let map = tcx. shallow_lint_levels_on ( owner) ;
145-
146- // All lints that appear with a non-allow level must be run.
147- for ( _, specs) in map. specs . iter ( ) {
148- for ( lint, level_and_source) in specs. iter ( ) {
149- if !matches ! ( level_and_source. level, Level :: Allow ) {
150- dont_need_to_run. remove ( lint) ;
151- }
152- }
165+ let will_run = tcx. lints_that_will_run_for_id ( owner) ;
166+ for lintid in will_run {
167+ dont_need_to_run. remove ( lintid) ;
153168 }
154169 }
155170
@@ -1009,7 +1024,12 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10091024}
10101025
10111026pub ( crate ) fn provide ( providers : & mut Providers ) {
1012- * providers = Providers { shallow_lint_levels_on, lints_that_dont_need_to_run, ..* providers } ;
1027+ * providers = Providers {
1028+ shallow_lint_levels_on,
1029+ lints_that_dont_need_to_run,
1030+ lints_that_will_run_for_id,
1031+ ..* providers
1032+ } ;
10131033}
10141034
10151035pub ( crate ) fn parse_lint_and_tool_name ( lint_name : & str ) -> ( Option < Symbol > , & str ) {
0 commit comments