1
Fork 0

Auto merge of #132666 - dingxiangfei2009:skip-if-let-rescope-lint, r=compiler-errors

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

Tracked by #124085
Related to https://github.com/rust-lang/rust/pull/131984#issuecomment-2448329667

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. 🙇
This commit is contained in:
bors 2025-01-23 23:16:06 +00:00
commit 22a220a1a8

View file

@ -9,7 +9,7 @@ use rustc_errors::{
use rustc_hir::{self as hir, HirIdSet}; use rustc_hir::{self as hir, HirIdSet};
use rustc_macros::LintDiagnostic; use rustc_macros::LintDiagnostic;
use rustc_middle::ty::TyCtxt; 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_session::{declare_lint, impl_lint_pass};
use rustc_span::Span; use rustc_span::Span;
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
@ -245,12 +245,12 @@ impl_lint_pass!(
impl<'tcx> LateLintPass<'tcx> for IfLetRescope { impl<'tcx> LateLintPass<'tcx> for IfLetRescope {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) {
if expr.span.edition().at_least_rust_2024() { if expr.span.edition().at_least_rust_2024()
return; || cx.tcx.lints_that_dont_need_to_run(()).contains(&LintId::of(IF_LET_RESCOPE))
} {
if let (Level::Allow, _) = cx.tcx.lint_level_at_node(IF_LET_RESCOPE, expr.hir_id) {
return; return;
} }
if let hir::ExprKind::Loop(block, _label, hir::LoopSource::While, _span) = expr.kind if let hir::ExprKind::Loop(block, _label, hir::LoopSource::While, _span) = expr.kind
&& let Some(value) = block.expr && let Some(value) = block.expr
&& let hir::ExprKind::If(cond, _conseq, _alt) = value.kind && let hir::ExprKind::If(cond, _conseq, _alt) = value.kind
@ -290,7 +290,6 @@ struct IfLetRescopeLint {
rewrite: Option<IfLetRescopeRewrite>, rewrite: Option<IfLetRescopeRewrite>,
} }
// #[derive(Subdiagnostic)]
struct IfLetRescopeRewrite { struct IfLetRescopeRewrite {
match_heads: Vec<SingleArmMatchBegin>, match_heads: Vec<SingleArmMatchBegin>,
consequent_heads: Vec<ConsequentRewrite>, consequent_heads: Vec<ConsequentRewrite>,