Skip to content

Commit

Permalink
Avoid stack overflow in generalizer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Dec 24, 2023
1 parent aa99688 commit 6d7f063
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/rustc_infer/src/infer/relate/generalize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::mem;

use rustc_data_structures::sso::SsoHashMap;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::DefId;
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
use rustc_middle::ty::error::TypeError;
Expand Down Expand Up @@ -226,7 +227,9 @@ where
let old_ambient_variance = self.ambient_variance;
self.ambient_variance = self.ambient_variance.xform(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;
Ok(r)
}
Expand Down

0 comments on commit 6d7f063

Please sign in to comment.