Skip to content

Commit 6c58e01

Browse files
authored
Rollup merge of #70277 - matthewjasper:remove-closurebound, r=nikomatsakis
Remove `ReClosureBound` We now substitute external names for regions in the query response. r? @nikomatsakis
2 parents 3184506 + c3b9881 commit 6c58e01

File tree

20 files changed

+50
-129
lines changed

20 files changed

+50
-129
lines changed

src/librustc/ich/impls_ty.rs

-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
9292
ty::ReFree(ref free_region) => {
9393
free_region.hash_stable(hcx, hasher);
9494
}
95-
ty::ReClosureBound(vid) => {
96-
vid.hash_stable(hcx, hasher);
97-
}
9895
ty::ReVar(..) | ty::RePlaceholder(..) => {
9996
bug!("StableHasher: unexpected region {:?}", *self)
10097
}

src/librustc/mir/query.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -88,34 +88,35 @@ pub struct ConstQualifs {
8888
/// requirements are then verified and proved by the closure's
8989
/// creating function. This struct encodes those requirements.
9090
///
91-
/// The requirements are listed as being between various
92-
/// `RegionVid`. The 0th region refers to `'static`; subsequent region
93-
/// vids refer to the free regions that appear in the closure (or
94-
/// generator's) type, in order of appearance. (This numbering is
95-
/// actually defined by the `UniversalRegions` struct in the NLL
96-
/// region checker. See for example
97-
/// `UniversalRegions::closure_mapping`.) Note that we treat the free
98-
/// regions in the closure's type "as if" they were erased, so their
99-
/// precise identity is not important, only their position.
91+
/// The requirements are listed as being between various `RegionVid`. The 0th
92+
/// region refers to `'static`; subsequent region vids refer to the free
93+
/// regions that appear in the closure (or generator's) type, in order of
94+
/// appearance. (This numbering is actually defined by the `UniversalRegions`
95+
/// struct in the NLL region checker. See for example
96+
/// `UniversalRegions::closure_mapping`.) Note the free regions in the
97+
/// closure's signature and captures are erased.
10098
///
10199
/// Example: If type check produces a closure with the closure substs:
102100
///
103101
/// ```text
104102
/// ClosureSubsts = [
105-
/// i8, // the "closure kind"
106-
/// for<'x> fn(&'a &'x u32) -> &'x u32, // the "closure signature"
107-
/// &'a String, // some upvar
103+
/// 'a, // From the parent.
104+
/// 'b,
105+
/// i8, // the "closure kind"
106+
/// for<'x> fn(&'<erased> &'x u32) -> &'x u32, // the "closure signature"
107+
/// &'<erased> String, // some upvar
108108
/// ]
109109
/// ```
110110
///
111-
/// here, there is one unique free region (`'a`) but it appears
112-
/// twice. We would "renumber" each occurrence to a unique vid, as follows:
111+
/// We would "renumber" each free region to a unique vid, as follows:
113112
///
114113
/// ```text
115114
/// ClosureSubsts = [
116-
/// i8, // the "closure kind"
117-
/// for<'x> fn(&'1 &'x u32) -> &'x u32, // the "closure signature"
118-
/// &'2 String, // some upvar
115+
/// '1, // From the parent.
116+
/// '2,
117+
/// i8, // the "closure kind"
118+
/// for<'x> fn(&'3 &'x u32) -> &'x u32, // the "closure signature"
119+
/// &'4 String, // some upvar
119120
/// ]
120121
/// ```
121122
///
@@ -124,14 +125,12 @@ pub struct ConstQualifs {
124125
/// can be extracted from its type and constrained to have the given
125126
/// outlives relationship.
126127
///
127-
/// In some cases, we have to record outlives requirements between
128-
/// types and regions as well. In that case, if those types include
129-
/// any regions, those regions are recorded as `ReClosureBound`
130-
/// instances assigned one of these same indices. Those regions will
131-
/// be substituted away by the creator. We use `ReClosureBound` in
132-
/// that case because the regions must be allocated in the global
133-
/// `TyCtxt`, and hence we cannot use `ReVar` (which is what we use
134-
/// internally within the rest of the NLL code).
128+
/// In some cases, we have to record outlives requirements between types and
129+
/// regions as well. In that case, if those types include any regions, those
130+
/// regions are recorded using their external names (`ReStatic`,
131+
/// `ReEarlyBound`, `ReFree`). We use these because in a query response we
132+
/// cannot use `ReVar` (which is what we use internally within the rest of the
133+
/// NLL code).
135134
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
136135
pub struct ClosureRegionRequirements<'tcx> {
137136
/// The number of external regions defined on the closure. In our

src/librustc/ty/print/pretty.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ impl<F: fmt::Write> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx, F> {
15741574

15751575
ty::ReVar(_) | ty::ReScope(_) | ty::ReErased => false,
15761576

1577-
ty::ReStatic | ty::ReEmpty(_) | ty::ReClosureBound(_) => true,
1577+
ty::ReStatic | ty::ReEmpty(_) => true,
15781578
}
15791579
}
15801580

@@ -1686,12 +1686,6 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, F> {
16861686
p!(write("'<empty:{:?}>", ui));
16871687
return Ok(self);
16881688
}
1689-
1690-
// The user should never encounter these in unsubstituted form.
1691-
ty::ReClosureBound(vid) => {
1692-
p!(write("{:?}", vid));
1693-
return Ok(self);
1694-
}
16951689
}
16961690

16971691
p!(write("'_"));

src/librustc/ty/structural_impls.rs

-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ impl fmt::Debug for ty::RegionKind {
8181
match *self {
8282
ty::ReEarlyBound(ref data) => write!(f, "ReEarlyBound({}, {})", data.index, data.name),
8383

84-
ty::ReClosureBound(ref vid) => write!(f, "ReClosureBound({:?})", vid),
85-
8684
ty::ReLateBound(binder_id, ref bound_region) => {
8785
write!(f, "ReLateBound({:?}, {:?})", binder_id, bound_region)
8886
}

src/librustc/ty/sty.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,6 @@ pub enum RegionKind {
13521352

13531353
/// Erased region, used by trait selection, in MIR and during codegen.
13541354
ReErased,
1355-
1356-
/// These are regions bound in the "defining type" for a
1357-
/// closure. They are used ONLY as part of the
1358-
/// `ClosureRegionRequirements` that are produced by MIR borrowck.
1359-
/// See `ClosureRegionRequirements` for more details.
1360-
ReClosureBound(RegionVid),
13611355
}
13621356

13631357
impl<'tcx> rustc_serialize::UseSpecializedDecodable for Region<'tcx> {}
@@ -1567,7 +1561,6 @@ impl RegionKind {
15671561
RegionKind::RePlaceholder(placeholder) => placeholder.name.is_named(),
15681562
RegionKind::ReEmpty(_) => false,
15691563
RegionKind::ReErased => false,
1570-
RegionKind::ReClosureBound(..) => false,
15711564
}
15721565
}
15731566

@@ -1648,9 +1641,6 @@ impl RegionKind {
16481641
ty::ReEmpty(_) | ty::ReStatic => {
16491642
flags = flags | TypeFlags::HAS_FREE_REGIONS;
16501643
}
1651-
ty::ReClosureBound(..) => {
1652-
flags = flags | TypeFlags::HAS_FREE_REGIONS;
1653-
}
16541644
ty::ReLateBound(..) => {
16551645
flags = flags | TypeFlags::HAS_RE_LATE_BOUND;
16561646
}

src/librustc_infer/infer/canonical/canonicalizer.rs

-4
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
336336
| ty::ReEmpty(_)
337337
| ty::RePlaceholder(..)
338338
| ty::ReErased => self.canonicalize_region_mode.canonicalize_free_region(self, r),
339-
340-
ty::ReClosureBound(..) => {
341-
bug!("closure bound region encountered during canonicalization");
342-
}
343339
}
344340
}
345341

src/librustc_infer/infer/combine.rs

-4
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,6 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
581581
return Ok(r);
582582
}
583583

584-
ty::ReClosureBound(..) => {
585-
span_bug!(self.span, "encountered unexpected ReClosureBound: {:?}", r,);
586-
}
587-
588584
ty::RePlaceholder(..)
589585
| ty::ReVar(..)
590586
| ty::ReEmpty(_)

src/librustc_infer/infer/error_reporting/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,6 @@ pub(super) fn note_and_explain_region(
152152
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
153153
(format!("lifetime {:?}", region), None)
154154
}
155-
156-
// We shouldn't encounter an error message with ReClosureBound.
157-
ty::ReClosureBound(..) => {
158-
bug!("encountered unexpected ReClosureBound: {:?}", region,);
159-
}
160155
};
161156

162157
emit_msg_span(err, prefix, description, span, suffix);

src/librustc_infer/infer/freshen.rs

-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
135135
// replace all free regions with 'erased
136136
self.tcx().lifetimes.re_erased
137137
}
138-
139-
ty::ReClosureBound(..) => {
140-
bug!("encountered unexpected region: {:?}", r,);
141-
}
142138
}
143139
}
144140

src/librustc_infer/infer/lexical_region_resolve/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -493,12 +493,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
493493
/// term "concrete regions").
494494
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
495495
let r = match (a, b) {
496-
(&ty::ReClosureBound(..), _)
497-
| (_, &ty::ReClosureBound(..))
498-
| (&ReLateBound(..), _)
499-
| (_, &ReLateBound(..))
500-
| (&ReErased, _)
501-
| (_, &ReErased) => {
496+
(&ReLateBound(..), _) | (_, &ReLateBound(..)) | (&ReErased, _) | (_, &ReErased) => {
502497
bug!("cannot relate region: LUB({:?}, {:?})", a, b);
503498
}
504499

src/librustc_infer/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
798798
| ty::ReEarlyBound(..) => ty::UniverseIndex::ROOT,
799799
ty::ReEmpty(ui) => ui,
800800
ty::RePlaceholder(placeholder) => placeholder.universe,
801-
ty::ReClosureBound(vid) | ty::ReVar(vid) => self.var_universe(vid),
801+
ty::ReVar(vid) => self.var_universe(vid),
802802
ty::ReLateBound(..) => bug!("universe(): encountered bound region {:?}", region),
803803
}
804804
}

src/librustc_mir/borrow_check/diagnostics/region_name.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
292292
| ty::ReVar(..)
293293
| ty::RePlaceholder(..)
294294
| ty::ReEmpty(_)
295-
| ty::ReErased
296-
| ty::ReClosureBound(..) => None,
295+
| ty::ReErased => None,
297296
}
298297
}
299298

src/librustc_mir/borrow_check/region_infer/mod.rs

+7-34
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
940940
/// inference variables with some region from the closure
941941
/// signature -- this is not always possible, so this is a
942942
/// fallible process. Presuming we do find a suitable region, we
943-
/// will represent it with a `ReClosureBound`, which is a
944-
/// `RegionKind` variant that can be allocated in the gcx.
943+
/// will use it's *external name*, which will be a `RegionKind`
944+
/// variant that can be used in query responses such as
945+
/// `ReEarlyBound`.
945946
fn try_promote_type_test_subject(
946947
&self,
947948
infcx: &InferCtxt<'_, 'tcx>,
@@ -991,14 +992,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
991992
// find an equivalent.
992993
let upper_bound = self.non_local_universal_upper_bound(region_vid);
993994
if self.region_contains(region_vid, upper_bound) {
994-
tcx.mk_region(ty::ReClosureBound(upper_bound))
995+
self.definitions[upper_bound].external_name.unwrap_or(r)
995996
} else {
996-
// In the case of a failure, use a `ReVar`
997-
// result. This will cause the `lift` later on to
998-
// fail.
997+
// In the case of a failure, use a `ReVar` result. This will
998+
// cause the `has_local_value` later on to return `None`.
999999
r
10001000
}
10011001
});
1002+
10021003
debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
10031004

10041005
// `has_local_value` will only be true if we failed to promote some region.
@@ -2029,15 +2030,6 @@ pub trait ClosureRegionRequirementsExt<'tcx> {
20292030
closure_def_id: DefId,
20302031
closure_substs: SubstsRef<'tcx>,
20312032
) -> Vec<QueryOutlivesConstraint<'tcx>>;
2032-
2033-
fn subst_closure_mapping<T>(
2034-
&self,
2035-
tcx: TyCtxt<'tcx>,
2036-
closure_mapping: &IndexVec<RegionVid, ty::Region<'tcx>>,
2037-
value: &T,
2038-
) -> T
2039-
where
2040-
T: TypeFoldable<'tcx>;
20412033
}
20422034

20432035
impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx> {
@@ -2094,7 +2086,6 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
20942086
}
20952087

20962088
ClosureOutlivesSubject::Ty(ty) => {
2097-
let ty = self.subst_closure_mapping(tcx, closure_mapping, &ty);
20982089
debug!(
20992090
"apply_requirements: ty={:?} \
21002091
outlived_region={:?} \
@@ -2107,22 +2098,4 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
21072098
})
21082099
.collect()
21092100
}
2110-
2111-
fn subst_closure_mapping<T>(
2112-
&self,
2113-
tcx: TyCtxt<'tcx>,
2114-
closure_mapping: &IndexVec<RegionVid, ty::Region<'tcx>>,
2115-
value: &T,
2116-
) -> T
2117-
where
2118-
T: TypeFoldable<'tcx>,
2119-
{
2120-
tcx.fold_regions(value, &mut false, |r, _depth| {
2121-
if let ty::ReClosureBound(vid) = r {
2122-
closure_mapping[*vid]
2123-
} else {
2124-
bug!("subst_closure_mapping: encountered non-closure bound free region {:?}", r)
2125-
}
2126-
})
2127-
}
21282101
}

src/librustc_trait_selection/opaque_types.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -816,11 +816,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> {
816816
// The regions that we expect from borrow checking.
817817
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReEmpty(ty::UniverseIndex::ROOT) => {}
818818

819-
ty::ReEmpty(_)
820-
| ty::RePlaceholder(_)
821-
| ty::ReVar(_)
822-
| ty::ReScope(_)
823-
| ty::ReClosureBound(_) => {
819+
ty::ReEmpty(_) | ty::RePlaceholder(_) | ty::ReVar(_) | ty::ReScope(_) => {
824820
// All of the regions in the type should either have been
825821
// erased by writeback, or mapped back to named regions by
826822
// borrow checking.

src/librustc_typeck/outlives/utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
170170

171171
// These regions don't appear in types from type declarations:
172172
RegionKind::ReErased
173-
| RegionKind::ReClosureBound(..)
174173
| RegionKind::ReScope(..)
175174
| RegionKind::ReVar(..)
176175
| RegionKind::RePlaceholder(..)

src/librustc_typeck/variance/constraints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
449449
}
450450

451451
ty::ReFree(..)
452-
| ty::ReClosureBound(..)
453452
| ty::ReScope(..)
454453
| ty::ReVar(..)
455454
| ty::RePlaceholder(..)

src/librustdoc/clean/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,6 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
450450
| ty::ReVar(..)
451451
| ty::RePlaceholder(..)
452452
| ty::ReEmpty(_)
453-
| ty::ReClosureBound(_)
454453
| ty::ReErased => {
455454
debug!("cannot clean region {:?}", self);
456455
None

src/test/ui/nll/ty-outlives/projection-one-region-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
111111
(),
112112
]
113113
= note: number of external vids: 4
114-
= note: where <T as Anything<ReClosureBound('_#2r)>>::AssocType: '_#3r
114+
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
115115

116116
note: no external requirements
117117
--> $DIR/projection-one-region-closure.rs:62:1

src/test/ui/nll/ty-outlives/projection-one-region-trait-bound-closure.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
9393
(),
9494
]
9595
= note: number of external vids: 4
96-
= note: where <T as Anything<ReClosureBound('_#2r)>>::AssocType: '_#3r
96+
= note: where <T as Anything<ReEarlyBound(1, 'b)>>::AssocType: '_#3r
9797

9898
note: no external requirements
9999
--> $DIR/projection-one-region-trait-bound-closure.rs:52:1

0 commit comments

Comments
 (0)