Skip to content

Commit 3bfcfd0

Browse files
fix var equality issue with old canonicalizer
1 parent 8d13454 commit 3bfcfd0

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
376376
}
377377
}
378378

379-
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
379+
fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
380380
match *t.kind() {
381-
ty::Infer(ty::TyVar(vid)) => {
381+
ty::Infer(ty::TyVar(mut vid)) => {
382+
// We need to canonicalize the *root* of our ty var.
383+
// This is so that our canonical response correctly reflects
384+
// any equated inference vars correctly!
385+
let root_vid = self.infcx.root_var(vid);
386+
if root_vid != vid {
387+
t = self.infcx.tcx.mk_ty_var(root_vid);
388+
vid = root_vid;
389+
}
390+
382391
debug!("canonical: type var found with vid {:?}", vid);
383392
match self.infcx.probe_ty_var(vid) {
384393
// `t` could be a float / int variable; canonicalize that instead.
@@ -469,9 +478,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
469478
}
470479
}
471480

472-
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
481+
fn fold_const(&mut self, mut ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
473482
match ct.kind() {
474-
ty::ConstKind::Infer(InferConst::Var(vid)) => {
483+
ty::ConstKind::Infer(InferConst::Var(mut vid)) => {
484+
// We need to canonicalize the *root* of our const var.
485+
// This is so that our canonical response correctly reflects
486+
// any equated inference vars correctly!
487+
let root_vid = self.infcx.root_const_var(vid);
488+
if root_vid != vid {
489+
ct = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), ct.ty());
490+
vid = root_vid;
491+
}
492+
475493
debug!("canonical: const var found with vid {:?}", vid);
476494
match self.infcx.probe_const_var(vid) {
477495
Ok(c) => {

compiler/rustc_trait_selection/src/solve/canonical/canonicalize.rs

-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
267267
// We need to canonicalize the *root* of our ty var.
268268
// This is so that our canonical response correctly reflects
269269
// any equated inference vars correctly!
270-
271270
let root_vid = self.infcx.root_var(vid);
272271
if root_vid != vid {
273272
t = self.infcx.tcx.mk_ty_var(root_vid);

0 commit comments

Comments
 (0)