From 5a219cba9563dc869577f7b7a9e318a1565dd4da Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 20 Sep 2024 14:17:08 +0000 Subject: [PATCH] bail if there are too many non-region infer vars --- .../src/solve/eval_ctxt/canonical.rs | 7 +++++++ tests/ui/traits/coherence-alias-hang.rs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs index 5acfec3dee3..3887f9c529c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/canonical.rs @@ -157,6 +157,13 @@ where }, ); + let num_non_region_vars = canonical.variables.iter().filter(|c| !c.is_region()).count(); + if num_non_region_vars > self.cx().recursion_limit() { + return Ok(self.make_ambiguous_response_no_constraints(MaybeCause::Overflow { + suggest_increasing_limit: true, + })); + } + Ok(canonical) } diff --git a/tests/ui/traits/coherence-alias-hang.rs b/tests/ui/traits/coherence-alias-hang.rs index 37b80739589..c2b4d2e42d2 100644 --- a/tests/ui/traits/coherence-alias-hang.rs +++ b/tests/ui/traits/coherence-alias-hang.rs @@ -1,4 +1,6 @@ //@ check-pass +//@ revisions: current next +//[next]@ compile-flags: -Znext-solver // Regression test for nalgebra hang .