Skip to content

Commit 3a5842a

Browse files
committed
add a new RegionKind variant: ReClosureBound
This is needed to allow the `ClosureRegionRequirements` to capture types that include regions.
1 parent 85e1d47 commit 3a5842a

File tree

13 files changed

+64
-1
lines changed

13 files changed

+64
-1
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ for ty::RegionKind {
7575
ty::ReFree(ref free_region) => {
7676
free_region.hash_stable(hcx, hasher);
7777
}
78+
ty::ReClosureBound(vid) => {
79+
vid.hash_stable(hcx, hasher);
80+
}
7881
ty::ReLateBound(..) |
7982
ty::ReVar(..) |
8083
ty::ReSkolemized(..) => {

src/librustc/infer/combine.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, '
475475
ty::Bivariant | ty::Covariant | ty::Contravariant => (),
476476
}
477477
}
478+
479+
ty::ReClosureBound(..) => {
480+
span_bug!(
481+
self.span,
482+
"encountered unexpected ReClosureBound: {:?}",
483+
r,
484+
);
485+
}
478486
}
479487

480488
// FIXME: This is non-ideal because we don't give a

src/librustc/infer/error_reporting/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
240240
ty::ReErased => {
241241
(format!("lifetime {:?}", region), None)
242242
}
243+
244+
// We shouldn't encounter an error message with ReClosureBound.
245+
ty::ReClosureBound(..) => {
246+
bug!(
247+
"encountered unexpected ReClosureBound: {:?}",
248+
region,
249+
);
250+
}
243251
};
244252
let message = format!("{}{}{}", prefix, description, suffix);
245253
if let Some(span) = span {

src/librustc/infer/freshen.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
113113
// replace all free regions with 'erased
114114
self.tcx().types.re_erased
115115
}
116+
117+
ty::ReClosureBound(..) => {
118+
bug!(
119+
"encountered unexpected ReClosureBound: {:?}",
120+
r,
121+
);
122+
}
116123
}
117124
}
118125

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
258258
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
259259
let tcx = self.region_rels.tcx;
260260
match (a, b) {
261-
(&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => {
261+
(&ty::ReClosureBound(..), _) |
262+
(_, &ty::ReClosureBound(..)) |
263+
(&ReLateBound(..), _) |
264+
(_, &ReLateBound(..)) |
265+
(&ReErased, _) |
266+
(_, &ReErased) => {
262267
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
263268
}
264269

src/librustc/mir/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,6 +1831,15 @@ pub struct GeneratorLayout<'tcx> {
18311831
/// instance of the closure is created, the corresponding free regions
18321832
/// can be extracted from its type and constrained to have the given
18331833
/// outlives relationship.
1834+
///
1835+
/// In some cases, we have to record outlives requirements between
1836+
/// types and regions as well. In that case, if those types include
1837+
/// any regions, those regions are recorded as `ReClosureBound`
1838+
/// instances assigned one of these same indices. Those regions will
1839+
/// be substituted away by the creator. We use `ReClosureBound` in
1840+
/// that case because the regions must be allocated in the global
1841+
/// TyCtxt, and hence we cannot use `ReVar` (which is what we use
1842+
/// internally within the rest of the NLL code).
18341843
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
18351844
pub struct ClosureRegionRequirements<'gcx> {
18361845
/// The number of external regions defined on the closure. In our

src/librustc/ty/sty.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,12 @@ pub enum RegionKind {
10361036

10371037
/// Erased region, used by trait selection, in MIR and during trans.
10381038
ReErased,
1039+
1040+
/// These are regions bound in the "defining type" for a
1041+
/// closure. They are used ONLY as part of the
1042+
/// `ClosureRegionRequirements` that are produced by MIR borrowck.
1043+
/// See `ClosureRegionRequirements` for more details.
1044+
ReClosureBound(RegionVid),
10391045
}
10401046

10411047
impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
@@ -1207,6 +1213,9 @@ impl RegionKind {
12071213
}
12081214
ty::ReErased => {
12091215
}
1216+
ty::ReClosureBound(..) => {
1217+
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1218+
}
12101219
}
12111220

12121221
match *self {

src/librustc/ty/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ impl<'a, 'gcx, 'tcx, W> TypeVisitor<'tcx> for TypeIdHasher<'a, 'gcx, 'tcx, W>
822822
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, .. }) => {
823823
self.def_id(def_id);
824824
}
825+
826+
ty::ReClosureBound(..) |
825827
ty::ReLateBound(..) |
826828
ty::ReFree(..) |
827829
ty::ReScope(..) |

src/librustc/util/ppaux.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ define_print! {
733733
ty::ReErased => Ok(()),
734734
ty::ReStatic => write!(f, "'static"),
735735
ty::ReEmpty => write!(f, "'<empty>"),
736+
737+
// The user should never encounter these in unsubstituted form.
738+
ty::ReClosureBound(vid) => write!(f, "{:?}", vid),
736739
}
737740
}
738741
debug {
@@ -743,6 +746,11 @@ define_print! {
743746
data.name)
744747
}
745748

749+
ty::ReClosureBound(ref vid) => {
750+
write!(f, "ReClosureBound({:?})",
751+
vid)
752+
}
753+
746754
ty::ReLateBound(binder_id, ref bound_region) => {
747755
write!(f, "ReLateBound({:?}, {:?})",
748756
binder_id,

src/librustc_borrowck/borrowck/gather_loans/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> {
367367
ty::ReStatic => self.item_ub,
368368

369369
ty::ReEmpty |
370+
ty::ReClosureBound(..) |
370371
ty::ReLateBound(..) |
371372
ty::ReVar(..) |
372373
ty::ReSkolemized(..) |

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
381381
},
382382
(RegionKind::ReLateBound(_, _), _) |
383383
(RegionKind::ReSkolemized(_, _), _) |
384+
(RegionKind::ReClosureBound(_), _) |
384385
(RegionKind::ReErased, _) => {
385386
span_bug!(drop_span, "region does not make sense in this context");
386387
},

src/librustc_typeck/variance/constraints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
465465
}
466466

467467
ty::ReFree(..) |
468+
ty::ReClosureBound(..) |
468469
ty::ReScope(..) |
469470
ty::ReVar(..) |
470471
ty::ReSkolemized(..) |

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
10551055
ty::ReVar(..) |
10561056
ty::ReSkolemized(..) |
10571057
ty::ReEmpty |
1058+
ty::ReClosureBound(_) |
10581059
ty::ReErased => None
10591060
}
10601061
}

0 commit comments

Comments
 (0)