Skip to content

Commit 4f0dc6c

Browse files
committed
generalize ClosureOutlivesSubjectTy
1 parent 00ded39 commit 4f0dc6c

File tree

2 files changed

+14
-15
lines changed
  • compiler

2 files changed

+14
-15
lines changed

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigi
1414
use rustc_middle::bug;
1515
use rustc_middle::mir::{
1616
AnnotationSource, BasicBlock, Body, ClosureOutlivesRequirement, ClosureOutlivesSubject,
17-
ClosureOutlivesSubjectTy, ClosureRegionRequirements, ConstraintCategory, Local, Location,
17+
ClosureRegionRequirements, ConstraintCategory, InClosureRequirement, Local, Location,
1818
ReturnConstraint, TerminatorKind,
1919
};
2020
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
@@ -1086,7 +1086,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10861086
return None;
10871087
}
10881088

1089-
Some(ClosureOutlivesSubject::Ty(ClosureOutlivesSubjectTy::bind(tcx, ty)))
1089+
Some(ClosureOutlivesSubject::Ty(InClosureRequirement::bind(tcx, ty)))
10901090
}
10911091

10921092
/// Like `universal_upper_bound`, but returns an approximation more suitable

compiler/rustc_middle/src/mir/query.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_index::bit_set::BitMatrix;
1111
use rustc_index::{Idx, IndexVec};
1212
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
1313
use rustc_span::{Span, Symbol};
14+
use rustc_type_ir::fold::TypeFoldable;
1415
use smallvec::SmallVec;
1516

1617
use super::{ConstValue, SourceInfo};
@@ -291,39 +292,37 @@ pub enum ClosureOutlivesSubject<'tcx> {
291292
/// Subject is a type, typically a type parameter, but could also
292293
/// be a projection. Indicates a requirement like `T: 'a` being
293294
/// passed to the caller, where the type here is `T`.
294-
Ty(ClosureOutlivesSubjectTy<'tcx>),
295+
Ty(InClosureRequirement<Ty<'tcx>>),
295296

296297
/// Subject is a free region from the closure. Indicates a requirement
297298
/// like `'a: 'b` being passed to the caller; the region here is `'a`.
298299
Region(ty::RegionVid),
299300
}
300301

301-
/// Represents a `ty::Ty` for use in [`ClosureOutlivesSubject`].
302-
///
303-
/// This abstraction is necessary because the type may include `ReVar` regions,
304-
/// which is what we use internally within NLL code, and they can't be used in
305-
/// a query response.
302+
/// Used for types in `ClosureOutlivesRequirements` which may refer to external
303+
/// regions. This is necessary as they are represented using `ReVar` which must
304+
/// not be used in a query response.
306305
///
307306
/// DO NOT implement `TypeVisitable` or `TypeFoldable` traits, because this
308307
/// type is not recognized as a binder for late-bound region.
309308
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
310-
pub struct ClosureOutlivesSubjectTy<'tcx> {
311-
inner: Ty<'tcx>,
309+
pub struct InClosureRequirement<T> {
310+
inner: T,
312311
}
313312

314-
impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
313+
impl<'tcx, T: TypeFoldable<TyCtxt<'tcx>>> InClosureRequirement<T> {
315314
/// All regions of `ty` must be of kind `ReVar` and must represent
316315
/// universal regions *external* to the closure.
317-
pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
318-
let inner = fold_regions(tcx, ty, |r, depth| match r.kind() {
316+
pub fn bind(tcx: TyCtxt<'tcx>, value: T) -> Self {
317+
let inner = fold_regions(tcx, value, |r, depth| match r.kind() {
319318
ty::ReVar(vid) => {
320319
let br = ty::BoundRegion {
321320
var: ty::BoundVar::new(vid.index()),
322321
kind: ty::BoundRegionKind::Anon,
323322
};
324323
ty::Region::new_bound(tcx, depth, br)
325324
}
326-
_ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),
325+
_ => bug!("unexpected region in closure requirement: {r:?}"),
327326
});
328327

329328
Self { inner }
@@ -333,7 +332,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
333332
self,
334333
tcx: TyCtxt<'tcx>,
335334
mut map: impl FnMut(ty::RegionVid) -> ty::Region<'tcx>,
336-
) -> Ty<'tcx> {
335+
) -> T {
337336
fold_regions(tcx, self.inner, |r, depth| match r.kind() {
338337
ty::ReBound(debruijn, br) => {
339338
debug_assert_eq!(debruijn, depth);

0 commit comments

Comments
 (0)