diff options
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/infer/combine.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/relate.rs | 11 |
2 files changed, 23 insertions, 2 deletions
diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 7770f2bd911..e38eebe23b1 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -543,6 +543,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { true } + fn visit_ct_substs(&self) -> bool { + true + } + fn binders<T>( &mut self, a: ty::Binder<T>, @@ -716,7 +720,10 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> { let variable_table = &mut inner.const_unification_table(); let var_value = variable_table.probe_value(vid); match var_value.val { - ConstVariableValue::Known { value: u } => self.relate(u, u), + ConstVariableValue::Known { value: u } => { + drop(inner); + self.relate(u, u) + } ConstVariableValue::Unknown { universe } => { if self.for_universe.can_name(universe) { Ok(c) @@ -815,6 +822,10 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { true } + fn visit_ct_substs(&self) -> bool { + true + } + fn relate_with_variance<T: Relate<'tcx>>( &mut self, _variance: ty::Variance, @@ -870,6 +881,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { } } } + ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) => Ok(t), _ => relate::super_relate_tys(self, t, t), } } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index af7fc429719..293b3c6b047 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -33,6 +33,15 @@ pub trait TypeRelation<'tcx>: Sized { /// relation. Just affects error messages. fn a_is_expected(&self) -> bool; + /// Whether we should look into the substs of unevaluated constants + /// even if `feature(const_evaluatable_checked)` is active. + /// + /// This is needed in `combine` to prevent accidentially creating + /// infinite types as we abuse `TypeRelation` to walk a type there. + fn visit_ct_substs(&self) -> bool { + false + } + fn with_cause<F, R>(&mut self, _cause: Cause, f: F) -> R where F: FnOnce(&mut Self) -> R, @@ -579,7 +588,7 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>( ( ty::ConstKind::Unevaluated(a_def, a_substs, None), ty::ConstKind::Unevaluated(b_def, b_substs, None), - ) if tcx.features().const_evaluatable_checked => { + ) if tcx.features().const_evaluatable_checked && !relation.visit_ct_substs() => { if tcx.try_unify_abstract_consts(((a_def, a_substs), (b_def, b_substs))) { Ok(a.val) } else { |
