@@ -2,8 +2,8 @@ use rustc_ast_pretty::pprust;
22use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
33use rustc_errors:: { Diag , LintDiagnostic , MultiSpan } ;
44use rustc_feature:: { Features , GateIssue } ;
5- use rustc_hir:: HirId ;
65use rustc_hir:: intravisit:: { self , Visitor } ;
6+ use rustc_hir:: { CRATE_HIR_ID , HirId } ;
77use rustc_index:: IndexVec ;
88use rustc_middle:: bug;
99use rustc_middle:: hir:: nested_filter;
@@ -118,12 +118,22 @@ impl LintLevelSets {
118118fn lints_that_dont_need_to_run ( tcx : TyCtxt < ' _ > , ( ) : ( ) ) -> FxIndexSet < LintId > {
119119 let store = unerased_lint_store ( & tcx. sess ) ;
120120
121+ let map = tcx. shallow_lint_levels_on ( rustc_hir:: CRATE_OWNER_ID ) ;
122+
121123 let dont_need_to_run: FxIndexSet < LintId > = store
122124 . get_lints ( )
123125 . into_iter ( )
124126 . 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+ }
127137 } else {
128138 None
129139 }
@@ -372,7 +382,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
372382 ) {
373383 let store = unerased_lint_store ( self . tcx . sess ) ;
374384 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
376386 // metalist (even with just one lint).
377387 let Some ( meta_item_list) = meta. meta_item_list ( ) else { return } ;
378388
@@ -387,7 +397,7 @@ impl<'tcx> Visitor<'tcx> for LintLevelMaximum<'tcx> {
387397 . collect :: < Vec < & str > > ( )
388398 . join ( "::" ) ;
389399 let Ok ( lints) = store. find_lints (
390- // SAFETY: Lint attributes can only have literals
400+ // Lint attributes can only have literals
391401 ident,
392402 ) else {
393403 return ;
0 commit comments