diff options
| author | Michael Goulet <michael@errs.io> | 2023-03-07 17:25:45 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2023-03-07 17:25:45 +0000 |
| commit | 3bfcfd079d41ba73228d382677688cd3ce088545 (patch) | |
| tree | d707eaa498d124abcfe26f839a0cbe11cb360567 /compiler/rustc_infer/src/infer | |
| parent | 8d13454498cf422c95352e96c1459f6904acde7b (diff) | |
| download | rust-3bfcfd079d41ba73228d382677688cd3ce088545.tar.gz rust-3bfcfd079d41ba73228d382677688cd3ce088545.zip | |
fix var equality issue with old canonicalizer
Diffstat (limited to 'compiler/rustc_infer/src/infer')
| -rw-r--r-- | compiler/rustc_infer/src/infer/canonical/canonicalizer.rs | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 678c4a0beb6..a29403cce2f 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -376,9 +376,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> { } } - fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { + fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> { match *t.kind() { - ty::Infer(ty::TyVar(vid)) => { + ty::Infer(ty::TyVar(mut vid)) => { + // We need to canonicalize the *root* of our ty var. + // This is so that our canonical response correctly reflects + // any equated inference vars correctly! + let root_vid = self.infcx.root_var(vid); + if root_vid != vid { + t = self.infcx.tcx.mk_ty_var(root_vid); + vid = root_vid; + } + debug!("canonical: type var found with vid {:?}", vid); match self.infcx.probe_ty_var(vid) { // `t` could be a float / int variable; canonicalize that instead. @@ -469,9 +478,18 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> { } } - fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { + fn fold_const(&mut self, mut ct: ty::Const<'tcx>) -> ty::Const<'tcx> { match ct.kind() { - ty::ConstKind::Infer(InferConst::Var(vid)) => { + ty::ConstKind::Infer(InferConst::Var(mut vid)) => { + // We need to canonicalize the *root* of our const var. + // This is so that our canonical response correctly reflects + // any equated inference vars correctly! + let root_vid = self.infcx.root_const_var(vid); + if root_vid != vid { + ct = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), ct.ty()); + vid = root_vid; + } + debug!("canonical: const var found with vid {:?}", vid); match self.infcx.probe_const_var(vid) { Ok(c) => { |
