Skip to content

Commit 97381d2

Browse files
committed
tweak ClosureOutlivesSubjectTy
1 parent 10da771 commit 97381d2

File tree

2 files changed

+11
-8
lines changed
  • compiler

2 files changed

+11
-8
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11531153
return None;
11541154
}
11551155

1156-
Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::new(tcx, ty)))
1156+
Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty)))
11571157
}
11581158

11591159
/// Returns a universally quantified region that outlives the

compiler/rustc_middle/src/mir/query.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -394,23 +394,26 @@ pub enum ClosureOutlivesSubject<'tcx> {
394394

395395
/// Represents a `ty::Ty` for use in [`ClosureOutlivesSubject`].
396396
///
397-
/// This indirection is necessary because the type may include `ReVar` regions,
398-
/// which is what we use internally within NLL code,
399-
/// and we can't use `ReVar`s in a query response.
397+
/// This abstraction is necessary because the type may include `ReVar` regions,
398+
/// which is what we use internally within NLL code, and they can't be used in
399+
/// a query response.
400+
///
401+
/// DO NOT implement `TypeVisitable` or `TypeFoldable` traits, because this
402+
/// type is not recognized as a binder for late-bound region.
400403
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
401404
pub struct ClosureOutlivesSubjectTy<'tcx> {
402405
inner: Ty<'tcx>,
403406
}
404407

405408
impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
406-
// All regions of `ty` must be of kind `ReVar`
407-
// and must point to an early-bound region in the closure's signature.
408-
pub fn new(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
409+
/// All regions of `ty` must be of kind `ReVar` and must represent
410+
/// universal regions *external* to the closure.
411+
pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
409412
let inner = tcx.fold_regions(ty, |r, depth| match r.kind() {
410413
ty::ReVar(vid) => {
411414
let br = ty::BoundRegion {
412415
var: ty::BoundVar::new(vid.index()),
413-
kind: ty::BrAnon(0u32, None),
416+
kind: ty::BrAnon(vid.as_u32(), None),
414417
};
415418
tcx.mk_re_late_bound(depth, br)
416419
}

0 commit comments

Comments
 (0)