about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2023-11-09 11:14:36 +0100
committerlcnr <rust@lcnr.de>2023-11-09 11:32:51 +0100
commit442e112d173b155e53dd0403b8202bbac05c4227 (patch)
tree8ee50e9821430bc1c4575721cead21df90da82a6
parent28e5c9505c1a2e06b5f3f1e8cce40878e56dee87 (diff)
downloadrust-442e112d173b155e53dd0403b8202bbac05c4227.tar.gz
rust-442e112d173b155e53dd0403b8202bbac05c4227.zip
update overflow handling for norm, add test
-rw-r--r--compiler/rustc_trait_selection/src/solve/assembly/mod.rs2
-rw-r--r--compiler/rustc_trait_selection/src/solve/mod.rs2
-rw-r--r--tests/ui/traits/new-solver/alias-relate/deeply-nested-no-hang.rs22
3 files changed, 24 insertions, 2 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
index 6feab0c1f09..13d7ebe1db0 100644
--- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs
@@ -352,7 +352,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         let &ty::Alias(_, projection_ty) = goal.predicate.self_ty().kind() else { return };
 
         candidates.extend(self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
-            if num_steps < ecx.local_overflow_limit() {
+            if tcx.recursion_limit().value_within_limit(num_steps) {
                 let normalized_ty = ecx.next_ty_infer();
                 let normalizes_to_goal = goal.with(
                     tcx,
diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs
index 5b44d396379..65d061ab3f4 100644
--- a/compiler/rustc_trait_selection/src/solve/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/mod.rs
@@ -310,7 +310,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
         depth: usize,
         ty: Ty<'tcx>,
     ) -> Option<Ty<'tcx>> {
-        if depth >= self.local_overflow_limit() {
+        if !self.tcx().recursion_limit().value_within_limit(depth) {
             return None;
         }
 
diff --git a/tests/ui/traits/new-solver/alias-relate/deeply-nested-no-hang.rs b/tests/ui/traits/new-solver/alias-relate/deeply-nested-no-hang.rs
new file mode 100644
index 00000000000..4abce7b57d5
--- /dev/null
+++ b/tests/ui/traits/new-solver/alias-relate/deeply-nested-no-hang.rs
@@ -0,0 +1,22 @@
+// check-pass
+// compile-flags: -Ztrait-solver=next
+// regression test for trait-system-refactor-initiative#68
+trait Identity {
+    type Assoc: ?Sized;
+}
+
+impl<T: ?Sized> Identity for T {
+    type Assoc = T;
+}
+
+type Id<T> = <T as Identity>::Assoc;
+
+type Five<T> = Id<Id<Id<Id<Id<T>>>>>;
+type Ty<T> = Five<Five<Five<Five<Five<T>>>>>;
+
+trait Trait<T> {}
+
+impl<T> Trait<T> for Ty<T> {}
+impl Trait<u32> for Ty<i32> {}
+
+fn main() {}