From a9caaf2725515f6c63ab7419e536c40229479835 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 2 Oct 2026 09:37:55 +0200 Subject: [PATCH] move everything into lint decorator --- .../src/solve/delegate.rs | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_trait_selection/src/solve/delegate.rs b/compiler/rustc_trait_selection/src/solve/delegate.rs index 8f2d496f95b25..fa55925687e29 100644 --- a/compiler/rustc_trait_selection/src/solve/delegate.rs +++ b/compiler/rustc_trait_selection/src/solve/delegate.rs @@ -515,27 +515,24 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< fn emit_next_solver_overflow_fcw(&self, goal: Goal<'tcx, ty::Predicate<'tcx>>, span: Span) { let tcx = self.tcx; - let goal = self.deeply_resolve_ignoring_regions(goal); - let mut visitor = OverflowedGoalChain { - span, - predicates: vec![], - recursion_limit: usize::min(16, tcx.recursion_limit().0), - }; - - // HACK: avoid computing goal chains for dependencies by relying on the fact that - // `cargo` passes `lint_cap=allow` to deps. This should mitigate some of the perf/rss - // regression when compiling crates whose deps trigger a large number of these FCWs. - if !matches!(tcx.sess.opts.lint_cap, Some(rustc_lint_defs::Level::Allow)) { - let _ = self.with_disabled_next_solver_overflow_fcw(|| { - self.visit_proof_tree(goal, &mut visitor) - }); - } - tcx.emit_node_span_lint( RECURSION_DEPTH_EXCEEDING_LIMIT, CRATE_HIR_ID, span, rustc_errors::DiagDecorator(|diag| { + // We do this in the decorator as that avoids the work + // if we don't actually emit the lint. + let goal = self.deeply_resolve_ignoring_regions(goal); + let mut visitor = OverflowedGoalChain { + span, + predicates: vec![], + recursion_limit: usize::min(16, tcx.recursion_limit().0), + }; + + let _ = self.with_disabled_next_solver_overflow_fcw(|| { + self.visit_proof_tree(goal, &mut visitor) + }); + // FIXME: share this with overflow error in fulfillment instead of duplicating. let pred_str = |pred: ty::Predicate<'tcx>| { let s = pred.to_string();