1
Fork 0

Avoid stack overflow in generalizer.

This commit is contained in:
Camille GILLOT 2023-12-24 20:05:16 +00:00
parent aa9968881c
commit 6d7f0632ed

View file

@ -1,6 +1,7 @@
use std::mem; use std::mem;
use rustc_data_structures::sso::SsoHashMap; use rustc_data_structures::sso::SsoHashMap;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue}; use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
@ -226,7 +227,9 @@ where
let old_ambient_variance = self.ambient_variance; let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(variance); self.ambient_variance = self.ambient_variance.xform(variance);
debug!(?self.ambient_variance, "new ambient variance"); debug!(?self.ambient_variance, "new ambient variance");
let r = self.relate(a, b)?; // Recursive calls to `relate` can overflow the stack. For example a deeper version of
// `ui/associated-consts/issue-93775.rs`.
let r = ensure_sufficient_stack(|| self.relate(a, b))?;
self.ambient_variance = old_ambient_variance; self.ambient_variance = old_ambient_variance;
Ok(r) Ok(r)
} }