Skip to content

Commit e97279b

Browse files
Don't run some MirLints if lints are not enabled
1 parent 2496008 commit e97279b

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

compiler/rustc_mir_transform/src/check_call_recursion.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_hir::LangItem;
77
use rustc_hir::def::DefKind;
88
use rustc_middle::mir::{self, BasicBlock, BasicBlocks, Body, Terminator, TerminatorKind};
99
use rustc_middle::ty::{self, GenericArg, GenericArgs, Instance, Ty, TyCtxt};
10+
use rustc_session::lint::LintId;
1011
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
1112
use rustc_span::Span;
1213

@@ -16,6 +17,10 @@ use crate::pass_manager::MirLint;
1617
pub(super) struct CheckCallRecursion;
1718

1819
impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
20+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
21+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
22+
}
23+
1924
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
2025
let def_id = body.source.def_id().expect_local();
2126

@@ -38,6 +43,10 @@ impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
3843
pub(super) struct CheckDropRecursion;
3944

4045
impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
46+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
47+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(UNCONDITIONAL_RECURSION))
48+
}
49+
4150
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
4251
let def_id = body.source.def_id().expect_local();
4352

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_hir::HirId;
22
use rustc_middle::mir::visit::Visitor;
33
use rustc_middle::mir::*;
44
use rustc_middle::ty::TyCtxt;
5+
use rustc_session::lint::LintId;
56
use rustc_session::lint::builtin::CONST_ITEM_MUTATION;
67
use rustc_span::Span;
78
use rustc_span::def_id::DefId;
@@ -11,6 +12,10 @@ use crate::errors;
1112
pub(super) struct CheckConstItemMutation;
1213

1314
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
15+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
16+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(CONST_ITEM_MUTATION))
17+
}
18+
1419
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1520
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1621
checker.visit_body(body);

compiler/rustc_mir_transform/src/errors.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
9292
}
9393

9494
impl AssertLintKind {
95+
pub(crate) fn all_lints() -> [&'static Lint; 2] {
96+
[lint::builtin::ARITHMETIC_OVERFLOW, lint::builtin::UNCONDITIONAL_PANIC]
97+
}
98+
9599
pub(crate) fn lint(&self) -> &'static Lint {
96100
match self {
97101
AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,

compiler/rustc_mir_transform/src/function_item_references.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_hir::def_id::DefId;
44
use rustc_middle::mir::visit::Visitor;
55
use rustc_middle::mir::*;
66
use rustc_middle::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt};
7+
use rustc_session::lint::LintId;
78
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
89
use rustc_span::source_map::Spanned;
910
use rustc_span::{Span, sym};
@@ -13,6 +14,10 @@ use crate::errors;
1314
pub(super) struct FunctionItemReferences;
1415

1516
impl<'tcx> crate::MirLint<'tcx> for FunctionItemReferences {
17+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
18+
!tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(FUNCTION_ITEM_REFERENCES))
19+
}
20+
1621
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1722
let mut checker = FunctionItemRefChecker { tcx, body };
1823
checker.visit_body(body);

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceC
1919
use rustc_middle::mir::*;
2020
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2121
use rustc_middle::ty::{self, ConstInt, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
22+
use rustc_session::lint::LintId;
2223
use rustc_span::Span;
2324
use tracing::{debug, instrument, trace};
2425

@@ -27,6 +28,11 @@ use crate::errors::{AssertLint, AssertLintKind};
2728
pub(super) struct KnownPanicsLint;
2829

2930
impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint {
31+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
32+
let ignored_lints = tcx.lints_that_dont_need_to_run(());
33+
!AssertLintKind::all_lints().iter().all(|lint| ignored_lints.contains(&LintId::of(lint)))
34+
}
35+
3036
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
3137
if body.tainted_by_errors.is_some() {
3238
return;

0 commit comments

Comments
 (0)