Skip to content

Commit 14f906f

Browse files
varkoryodaldevoid
andcommitted
Define canonicalize_const_var
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent 0728b62 commit 14f906f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/librustc/infer/canonical/canonicalizer.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,4 +633,34 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
633633
self.tcx().mk_ty(ty::Bound(self.binder_index, var.into()))
634634
}
635635
}
636+
637+
/// Given a type variable `const_var` of the given kind, first check
638+
/// if `const_var` is bound to anything; if so, canonicalize
639+
/// *that*. Otherwise, create a new canonical variable for
640+
/// `const_var`.
641+
fn canonicalize_const_var(
642+
&mut self,
643+
info: CanonicalVarInfo,
644+
const_var: &'tcx ty::LazyConst<'tcx>
645+
) -> &'tcx ty::LazyConst<'tcx> {
646+
let infcx = self.infcx.expect("encountered const-var without infcx");
647+
let bound_to = infcx.resolve_const_var(const_var);
648+
if bound_to != const_var {
649+
self.fold_const(bound_to)
650+
} else {
651+
let ty = match const_var {
652+
ty::LazyConst::Unevaluated(def_id, _) => {
653+
self.tcx.type_of(*def_id)
654+
}
655+
ty::LazyConst::Evaluated(ty::Const { ty, .. }) => ty,
656+
};
657+
let var = self.canonical_var(info, const_var.into());
658+
self.tcx().mk_lazy_const(
659+
ty::LazyConst::Evaluated(ty::Const {
660+
val: ConstValue::Infer(InferConst::Canonical(self.binder_index, var.into())),
661+
ty,
662+
})
663+
)
664+
}
665+
}
636666
}

0 commit comments

Comments
 (0)