avoid instantiating infer vars with infer
This commit is contained in:
parent
7df0c211ac
commit
40aa9f4fd9
2 changed files with 9 additions and 4 deletions
|
@ -34,6 +34,7 @@ use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue, EffectVa
|
|||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
||||
use rustc_middle::ty::error::{ExpectedFound, TypeError};
|
||||
use rustc_middle::ty::relate::{RelateResult, TypeRelation};
|
||||
use rustc_middle::ty::TyVar;
|
||||
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{IntType, UintType};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
@ -459,7 +460,12 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
|
|||
ambient_variance,
|
||||
)?;
|
||||
|
||||
self.infcx.inner.borrow_mut().type_variables().instantiate(b_vid, b_ty);
|
||||
// Constrain `b_vid` to the generalized type `b_ty`.
|
||||
if let &ty::Infer(TyVar(b_ty_vid)) = b_ty.kind() {
|
||||
self.infcx.inner.borrow_mut().type_variables().equate(b_vid, b_ty_vid);
|
||||
} else {
|
||||
self.infcx.inner.borrow_mut().type_variables().instantiate(b_vid, b_ty);
|
||||
}
|
||||
|
||||
if needs_wf {
|
||||
self.obligations.push(Obligation::new(
|
||||
|
|
|
@ -229,12 +229,11 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
|
|||
/// Precondition: `vid` must not have been previously instantiated.
|
||||
pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
|
||||
let vid = self.root_var(vid);
|
||||
debug_assert!(!ty.is_ty_var(), "instantiating ty var with var: {vid:?} {ty:?}");
|
||||
debug_assert!(self.probe(vid).is_unknown());
|
||||
debug_assert!(
|
||||
self.eq_relations().probe_value(vid).is_unknown(),
|
||||
"instantiating type variable `{:?}` twice: new-value = {:?}, old-value={:?}",
|
||||
vid,
|
||||
ty,
|
||||
"instantiating type variable `{vid:?}` twice: new-value = {ty:?}, old-value={:?}",
|
||||
self.eq_relations().probe_value(vid)
|
||||
);
|
||||
self.eq_relations().union_value(vid, TypeVariableValue::Known { value: ty });
|
||||
|
|
Loading…
Add table
Reference in a new issue