Skip to content

Commit

Permalink
Auto merge of rust-lang#132666 - dingxiangfei2009:skip-if-let-rescope…
Browse files Browse the repository at this point in the history
…-lint, r=<try>

Skip `if-let-rescope` lint unless requested by migration

Tracked by rust-lang#124085
Related to rust-lang#131984 (comment)

Given that `if-let-rescope` is a lint to be enabled globally by an edition migration, there is no point in extracting the precise lint level on the HIR expression. This mitigates the performance regression discovered by the earlier perf-run.

cc `@Kobzol` `@rylev` `@traviscross` I propose a `rust-timer` run to measure how much performance that we can recover from the mitigation. 🙇
  • Loading branch information
bors committed Nov 6, 2024
2 parents bc5cf99 + 193fe5a commit 748da1d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions compiler/rustc_lint/src/if_let_rescope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_errors::{
use rustc_hir::{self as hir, HirIdSet};
use rustc_macros::LintDiagnostic;
use rustc_middle::ty::TyCtxt;
use rustc_session::lint::{FutureIncompatibilityReason, Level};
use rustc_session::lint::{FutureIncompatibilityReason, LintId};
use rustc_session::{declare_lint, impl_lint_pass};
use rustc_span::Span;
use rustc_span::edition::Edition;
Expand Down Expand Up @@ -242,12 +242,12 @@ impl_lint_pass!(

impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
if expr.span.edition().at_least_rust_2024() {
return;
}
if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) {
if expr.span.edition().at_least_rust_2024()
|| cx.tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(IF_LET_RESCOPE))
{
return;
}

if let hir::ExprKind::Loop(block, _label, hir::LoopSource::While, _span) = expr.kind
&& let Some(value) = block.expr
&& let hir::ExprKind::If(cond, _conseq, _alt) = value.kind
Expand Down Expand Up @@ -287,7 +287,6 @@ struct IfLetRescopeLint {
rewrite: Option<IfLetRescopeRewrite>,
}

// #[derive(Subdiagnostic)]
struct IfLetRescopeRewrite {
match_heads: Vec<SingleArmMatchBegin>,
consequent_heads: Vec<ConsequentRewrite>,
Expand Down

0 comments on commit 748da1d

Please sign in to comment.