about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-03-04 11:19:56 +0300
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-03-04 11:19:56 +0300
commit97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d (patch)
tree2773682ff6e564258d7d4b126ff0963234be7e3d /compiler/rustc_middle/src/mir
parent10da7710cdd5d76261bcfcf31dd163c966b3ebb3 (diff)
downloadrust-97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d.tar.gz
rust-97381d2f1ef6481e201eb8fb8bbc1c5ddeffb61d.zip
tweak ClosureOutlivesSubjectTy
Diffstat (limited to 'compiler/rustc_middle/src/mir')
-rw-r--r--compiler/rustc_middle/src/mir/query.rs17
1 files changed, 10 insertions, 7 deletions
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)
             }