Skip to content

Commit 2724389

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

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

compiler/rustc_mir_transform/src/check_call_recursion.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use crate::pass_manager::MirLint;
1616
pub(super) struct CheckCallRecursion;
1717

1818
impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
19+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
20+
!tcx.lints_that_dont_need_to_run(()).contains(&UNCONDITIONAL_RECURSION)
21+
}
22+
1923
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
2024
let def_id = body.source.def_id().expect_local();
2125

@@ -38,6 +42,10 @@ impl<'tcx> MirLint<'tcx> for CheckCallRecursion {
3842
pub(super) struct CheckDropRecursion;
3943

4044
impl<'tcx> MirLint<'tcx> for CheckDropRecursion {
45+
fn is_enabled(&self, _tcx: TyCtxt<'tcx>) -> bool {
46+
!tcx.lints_that_dont_need_to_run(()).contains(&UNCONDITIONAL_RECURSION)
47+
}
48+
4149
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
4250
let def_id = body.source.def_id().expect_local();
4351

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ use crate::errors;
1111
pub(super) struct CheckConstItemMutation;
1212

1313
impl<'tcx> crate::MirLint<'tcx> for CheckConstItemMutation {
14+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
15+
!tcx.lints_that_dont_need_to_run(()).contains(&CONST_ITEM_MUTATION)
16+
}
17+
1418
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1519
let mut checker = ConstMutationChecker { body, tcx, target_local: None };
1620
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] {
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ use crate::errors;
1313
pub(super) struct FunctionItemReferences;
1414

1515
impl<'tcx> crate::MirLint<'tcx> for FunctionItemReferences {
16+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
17+
!tcx.lints_that_dont_need_to_run(()).contains(&FUNCTION_ITEM_REFERENCES)
18+
}
19+
1620
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1721
let mut checker = FunctionItemRefChecker { tcx, body };
1822
checker.visit_body(body);

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ use crate::errors::{AssertLint, AssertLintKind};
2727
pub(super) struct KnownPanicsLint;
2828

2929
impl<'tcx> crate::MirLint<'tcx> for KnownPanicsLint {
30+
fn is_enabled(&self, tcx: TyCtxt<'tcx>) -> bool {
31+
let ignored_lints = tcx.lints_that_dont_need_to_run(());
32+
!AssertLintKind::all_lints().all(|lint| ignored_lints.contains(lint))
33+
}
34+
3035
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
3136
if body.tainted_by_errors.is_some() {
3237
return;

0 commit comments

Comments
 (0)