summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_trait_selection/src/solve/canonicalize.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /compiler/rustc_trait_selection/src/solve/canonicalize.rs
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_trait_selection/src/solve/canonicalize.rs')
-rw-r--r--compiler/rustc_trait_selection/src/solve/canonicalize.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/canonicalize.rs b/compiler/rustc_trait_selection/src/solve/canonicalize.rs
index ff4bff10c..255620489 100644
--- a/compiler/rustc_trait_selection/src/solve/canonicalize.rs
+++ b/compiler/rustc_trait_selection/src/solve/canonicalize.rs
@@ -208,8 +208,25 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
t
}
- fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
- let r = self.infcx.shallow_resolve(r);
+ fn fold_region(&mut self, mut r: ty::Region<'tcx>) -> ty::Region<'tcx> {
+ match self.canonicalize_mode {
+ CanonicalizeMode::Input => {
+ // Don't resolve infer vars in input, since it affects
+ // caching and may cause trait selection bugs which rely
+ // on regions to be equal.
+ }
+ CanonicalizeMode::Response { .. } => {
+ if let ty::ReVar(vid) = *r {
+ r = self
+ .infcx
+ .inner
+ .borrow_mut()
+ .unwrap_region_constraints()
+ .opportunistic_resolve_var(self.infcx.tcx, vid);
+ }
+ }
+ }
+
let kind = match *r {
ty::ReLateBound(..) => return r,
@@ -255,7 +272,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
}),
);
let br = ty::BoundRegion { var, kind: BrAnon(None) };
- self.interner().mk_re_late_bound(self.binder_index, br)
+ ty::Region::new_late_bound(self.interner(), self.binder_index, br)
}
fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> {
@@ -266,7 +283,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
// 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);
+ t = Ty::new_var(self.infcx.tcx, root_vid);
vid = root_vid;
}
@@ -349,7 +366,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
}),
);
let bt = ty::BoundTy { var, kind: BoundTyKind::Anon };
- self.interner().mk_bound(self.binder_index, bt)
+ Ty::new_bound(self.infcx.tcx, self.binder_index, bt)
}
fn fold_const(&mut self, mut c: ty::Const<'tcx>) -> ty::Const<'tcx> {
@@ -360,7 +377,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
// any equated inference vars correctly!
let root_vid = self.infcx.root_const_var(vid);
if root_vid != vid {
- c = self.infcx.tcx.mk_const(ty::InferConst::Var(root_vid), c.ty());
+ c = ty::Const::new_var(self.infcx.tcx, root_vid, c.ty());
vid = root_vid;
}
@@ -409,6 +426,6 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'_, 'tcx> {
var
}),
);
- self.interner().mk_const(ty::ConstKind::Bound(self.binder_index, var), c.ty())
+ ty::Const::new_bound(self.infcx.tcx, self.binder_index, var, c.ty())
}
}