From fafe66d4383c7d5b071b9cc5bf5f4efda23a1a08 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Tue, 5 Dec 2023 15:13:08 +0000 Subject: [PATCH] don't resolve regions in query input fixes a soundness regression described in the PR description. --- .../src/infer/canonical/canonicalizer.rs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index ed4de390000..69cc0713b25 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -202,8 +202,21 @@ impl CanonicalizeMode for CanonicalizeQueryResponse { fn canonicalize_free_region<'tcx>( &self, canonicalizer: &mut Canonicalizer<'_, 'tcx>, - r: ty::Region<'tcx>, + mut r: ty::Region<'tcx>, ) -> ty::Region<'tcx> { + if let ty::ReVar(vid) = *r { + r = canonicalizer + .infcx + .inner + .borrow_mut() + .unwrap_region_constraints() + .opportunistic_resolve_var(canonicalizer.tcx, vid); + debug!( + "canonical: region var found with vid {vid:?}, \ + opportunistically resolved to {r:?}", + ); + }; + match *r { ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r, @@ -381,25 +394,12 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { } } - ty::ReVar(vid) => { - let resolved = self - .infcx - .inner - .borrow_mut() - .unwrap_region_constraints() - .opportunistic_resolve_var(self.tcx, vid); - debug!( - "canonical: region var found with vid {vid:?}, \ - opportunistically resolved to {resolved:?}", - ); - self.canonicalize_mode.canonicalize_free_region(self, resolved) - } - ty::ReStatic | ty::ReEarlyParam(..) | ty::ReError(_) | ty::ReLateParam(_) | ty::RePlaceholder(..) + | ty::ReVar(_) | ty::ReErased => self.canonicalize_mode.canonicalize_free_region(self, r), } }