Skip to content

Commit 6d7f063

Browse files
committed
Avoid stack overflow in generalizer.
1 parent aa99688 commit 6d7f063

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

compiler/rustc_infer/src/infer/relate/generalize.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::mem;
22

33
use rustc_data_structures::sso::SsoHashMap;
4+
use rustc_data_structures::stack::ensure_sufficient_stack;
45
use rustc_hir::def_id::DefId;
56
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
67
use rustc_middle::ty::error::TypeError;
@@ -226,7 +227,9 @@ where
226227
let old_ambient_variance = self.ambient_variance;
227228
self.ambient_variance = self.ambient_variance.xform(variance);
228229
debug!(?self.ambient_variance, "new ambient variance");
229-
let r = self.relate(a, b)?;
230+
// Recursive calls to `relate` can overflow the stack. For example a deeper version of
231+
// `ui/associated-consts/issue-93775.rs`.
232+
let r = ensure_sufficient_stack(|| self.relate(a, b))?;
230233
self.ambient_variance = old_ambient_variance;
231234
Ok(r)
232235
}

0 commit comments

Comments
 (0)