From 97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Sat, 4 Mar 2023 11:19:56 +0300 Subject: [PATCH] tweak ClosureOutlivesSubjectTy --- compiler/rustc_borrowck/src/region_infer/mod.rs | 2 +- compiler/rustc_middle/src/mir/query.rs | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 3137e71781c..74ea2451348 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1153,7 +1153,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { return None; } - Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::new(tcx, ty))) + Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty))) } /// Returns a universally quantified region that outlives the diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index 87a2b9ec73e..b964c1852d2 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -394,23 +394,26 @@ pub enum ClosureOutlivesSubject<'tcx> { /// Represents a `ty::Ty` for use in [`ClosureOutlivesSubject`]. /// -/// This indirection is necessary because the type may include `ReVar` regions, -/// which is what we use internally within NLL code, -/// and we can't use `ReVar`s in a query response. +/// This abstraction is necessary because the type may include `ReVar` regions, +/// which is what we use internally within NLL code, and they can't be used in +/// a query response. +/// +/// DO NOT implement `TypeVisitable` or `TypeFoldable` traits, because this +/// type is not recognized as a binder for late-bound region. #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct ClosureOutlivesSubjectTy<'tcx> { inner: Ty<'tcx>, } impl<'tcx> ClosureOutlivesSubjectTy<'tcx> { - // All regions of `ty` must be of kind `ReVar` - // and must point to an early-bound region in the closure's signature. - pub fn new(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self { + /// All regions of `ty` must be of kind `ReVar` and must represent + /// universal regions *external* to the closure. + pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self { let inner = tcx.fold_regions(ty, |r, depth| match r.kind() { ty::ReVar(vid) => { let br = ty::BoundRegion { var: ty::BoundVar::new(vid.index()), - kind: ty::BrAnon(0u32, None), + kind: ty::BrAnon(vid.as_u32(), None), }; tcx.mk_re_late_bound(depth, br) }