diff options
| author | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-03-04 11:19:56 +0300 |
|---|---|---|
| committer | Ali MJ Al-Nasrawy <alimjalnasrawy@gmail.com> | 2023-03-04 11:19:56 +0300 |
| commit | 97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d (patch) | |
| tree | 2773682ff6e564258d7d4b126ff0963234be7e3d | |
| parent | 10da7710cdd5d76261bcfcf31dd163c966b3ebb3 (diff) | |
| download | rust-97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d.tar.gz rust-97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d.zip | |
tweak ClosureOutlivesSubjectTy
| -rw-r--r-- | compiler/rustc_borrowck/src/region_infer/mod.rs | 2 | ||||
| -rw-r--r-- | 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) } |
