@@ -2,8 +2,8 @@ use rustc_ast_pretty::pprust;
2
2
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
3
3
use rustc_errors:: { Diag , LintDiagnostic , MultiSpan } ;
4
4
use rustc_feature:: { Features , GateIssue } ;
5
- use rustc_hir:: HirId ;
6
5
use rustc_hir:: intravisit:: { self , Visitor } ;
6
+ use rustc_hir:: { CRATE_HIR_ID , HirId } ;
7
7
use rustc_index:: IndexVec ;
8
8
use rustc_middle:: bug;
9
9
use rustc_middle:: hir:: nested_filter;
@@ -118,12 +118,22 @@ impl LintLevelSets {
118
118
fn lints_that_dont_need_to_run ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> FxIndexSet < LintId > {
119
119
let store = unerased_lint_store ( & tcx. sess ) ;
120
120
121
+ let map = tcx. shallow_lint_levels_on ( rustc_hir:: CRATE_OWNER_ID ) ;
122
+
121
123
let dont_need_to_run: FxIndexSet < LintId > = store
122
124
. get_lints ( )
123
125
. into_iter ( )
124
126
. filter_map ( |lint| {
125
- if !lint. eval_always && lint. default_level ( tcx. sess . edition ( ) ) == Level :: Allow {
126
- Some ( LintId :: of ( lint) )
127
+ if !lint. eval_always {
128
+ let lint_level = map. lint_level_id_at_node ( tcx, LintId :: of ( lint) , CRATE_HIR_ID ) ;
129
+ if matches ! ( lint_level, ( Level :: Allow , ..) )
130
+ || ( matches ! ( lint_level, ( .., LintLevelSource :: Default ) ) )
131
+ && lint. default_level ( tcx. sess . edition ( ) ) == Level :: Allow
132
+ {
133
+ Some ( LintId :: of ( lint) )
134
+ } else {
135
+ None
136
+ }
127
137
} else {
128
138
None
129
139
}
@@ -372,7 +382,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
372
382
) {
373
383
let store = unerased_lint_store ( self . tcx . sess ) ;
374
384
let Some ( meta) = attribute. meta ( ) else { return } ;
375
- // SAFETY: Lint attributes are always a metalist inside a
385
+ // Lint attributes are always a metalist inside a
376
386
// metalist (even with just one lint).
377
387
let Some ( meta_item_list) = meta. meta_item_list ( ) else { return } ;
378
388
@@ -387,7 +397,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
387
397
. collect :: < Vec < & str > > ( )
388
398
. join ( "::" ) ;
389
399
let Ok ( lints) = store. find_lints (
390
- // SAFETY: Lint attributes can only have literals
400
+ // Lint attributes can only have literals
391
401
ident,
392
402
) else {
393
403
return ;
0 commit comments