Skip to content

Commit b0c34e1

Browse files
committed
Moved struct Placeholder<T>
1 parent 9b82a4f commit b0c34e1

File tree

34 files changed

+296
-246
lines changed

34 files changed

+296
-246
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<'tcx> UniverseInfo<'tcx> {
5252
pub(crate) fn report_erroneous_element(
5353
&self,
5454
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
55-
placeholder: ty::PlaceholderRegion,
56-
error_element: RegionElement,
55+
placeholder: ty::PlaceholderRegion<'tcx>,
56+
error_element: RegionElement<'tcx>,
5757
cause: ObligationCause<'tcx>,
5858
) {
5959
match *self {
@@ -152,8 +152,8 @@ pub(crate) trait TypeOpInfo<'tcx> {
152152
fn report_erroneous_element(
153153
&self,
154154
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
155-
placeholder: ty::PlaceholderRegion,
156-
error_element: RegionElement,
155+
placeholder: ty::PlaceholderRegion<'tcx>,
156+
error_element: RegionElement<'tcx>,
157157
cause: ObligationCause<'tcx>,
158158
) {
159159
let tcx = mbcx.infcx.tcx;
@@ -169,23 +169,22 @@ pub(crate) trait TypeOpInfo<'tcx> {
169169

170170
let placeholder_region = ty::Region::new_placeholder(
171171
tcx,
172-
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
172+
ty::bound::Placeholder::new(adjusted_universe.into(), placeholder.bound),
173173
);
174174

175-
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
176-
error_element
177-
{
178-
let adjusted_universe =
179-
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
180-
adjusted_universe.map(|adjusted| {
181-
ty::Region::new_placeholder(
182-
tcx,
183-
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
184-
)
185-
})
186-
} else {
187-
None
188-
};
175+
let error_region =
176+
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
177+
let adjusted_universe =
178+
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
179+
adjusted_universe.map(|adjusted| {
180+
ty::Region::new_placeholder(
181+
tcx,
182+
ty::bound::Placeholder::new(adjusted.into(), error_placeholder.bound),
183+
)
184+
})
185+
} else {
186+
None
187+
};
189188

190189
debug!(?placeholder_region);
191190

@@ -440,7 +439,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
440439
placeholder_region: ty::Region<'tcx>,
441440
error_region: Option<ty::Region<'tcx>>,
442441
region_constraints: &RegionConstraintData<'tcx>,
443-
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
442+
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin<'tcx>,
444443
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
445444
) -> Option<Diag<'a>> {
446445
let placeholder_universe = match placeholder_region.kind() {

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
109109
/// The placeholder free region.
110110
longer_fr: RegionVid,
111111
/// The region element that erroneously must be outlived by `longer_fr`.
112-
error_element: RegionElement,
112+
error_element: RegionElement<'tcx>,
113113
/// The placeholder region.
114-
placeholder: ty::PlaceholderRegion,
114+
placeholder: ty::PlaceholderRegion<'tcx>,
115115
},
116116

117117
/// Any other lifetime error.
118118
RegionError {
119119
/// The origin of the region.
120-
fr_origin: NllRegionVariableOrigin,
120+
fr_origin: NllRegionVariableOrigin<'tcx>,
121121
/// The region that should outlive `shorter_fr`.
122122
longer_fr: RegionVid,
123123
/// The region that should be shorter, but we can't prove it.
@@ -427,7 +427,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
427427
pub(crate) fn report_region_error(
428428
&mut self,
429429
fr: RegionVid,
430-
fr_origin: NllRegionVariableOrigin,
430+
fr_origin: NllRegionVariableOrigin<'tcx>,
431431
outlived_fr: RegionVid,
432432
outlives_suggestion: &mut OutlivesSuggestionBuilder,
433433
) {

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) struct LoweredConstraints<'tcx> {
3232
pub(crate) type_tests: Vec<TypeTest<'tcx>>,
3333
pub(crate) liveness_constraints: LivenessValues,
3434
pub(crate) universe_causes: FxIndexMap<UniverseIndex, UniverseInfo<'tcx>>,
35-
pub(crate) placeholder_indices: PlaceholderIndices,
35+
pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
3636
}
3737

3838
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {

compiler/rustc_borrowck/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
661661

662662
pub(crate) fn next_region_var<F>(
663663
&self,
664-
origin: RegionVariableOrigin,
664+
origin: RegionVariableOrigin<'tcx>,
665665
get_ctxt_fn: F,
666666
) -> ty::Region<'tcx>
667667
where
@@ -683,7 +683,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
683683
#[instrument(skip(self, get_ctxt_fn), level = "debug")]
684684
pub(crate) fn next_nll_region_var<F>(
685685
&self,
686-
origin: NllRegionVariableOrigin,
686+
origin: NllRegionVariableOrigin<'tcx>,
687687
get_ctxt_fn: F,
688688
) -> ty::Region<'tcx>
689689
where

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct RegionInferenceContext<'tcx> {
110110
/// The final inferred values of the region variables; we compute
111111
/// one value per SCC. To get the value for any given *region*,
112112
/// you first find which scc it is a part of.
113-
scc_values: RegionValues<ConstraintSccIndex>,
113+
scc_values: RegionValues<'tcx, ConstraintSccIndex>,
114114

115115
/// Type constraints that we check after solving.
116116
type_tests: Vec<TypeTest<'tcx>>,
@@ -125,7 +125,7 @@ pub(crate) struct RegionDefinition<'tcx> {
125125
/// What kind of variable is this -- a free region? existential
126126
/// variable? etc. (See the `NllRegionVariableOrigin` for more
127127
/// info.)
128-
pub(crate) origin: NllRegionVariableOrigin,
128+
pub(crate) origin: NllRegionVariableOrigin<'tcx>,
129129

130130
/// Which universe is this region variable defined in? This is
131131
/// most often `ty::UniverseIndex::ROOT`, but when we encounter
@@ -453,7 +453,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
453453
/// Returns `true` if the region `r` contains the point `p`.
454454
///
455455
/// Panics if called before `solve()` executes,
456-
pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex) -> bool {
456+
pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex<'tcx>) -> bool {
457457
let scc = self.constraint_sccs.scc(r);
458458
self.scc_values.contains(scc, p)
459459
}
@@ -481,7 +481,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
481481
pub(crate) fn placeholders_contained_in(
482482
&self,
483483
r: RegionVid,
484-
) -> impl Iterator<Item = ty::PlaceholderRegion> {
484+
) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
485485
let scc = self.constraint_sccs.scc(r);
486486
self.scc_values.placeholders_contained_in(scc)
487487
}
@@ -1311,7 +1311,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13111311
fn check_bound_universal_region(
13121312
&self,
13131313
longer_fr: RegionVid,
1314-
placeholder: ty::PlaceholderRegion,
1314+
placeholder: ty::PlaceholderRegion<'tcx>,
13151315
errors_buffer: &mut RegionErrors<'tcx>,
13161316
) {
13171317
debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,);
@@ -1523,7 +1523,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15231523
pub(crate) fn region_from_element(
15241524
&self,
15251525
longer_fr: RegionVid,
1526-
element: &RegionElement,
1526+
element: &RegionElement<'tcx>,
15271527
) -> RegionVid {
15281528
match *element {
15291529
RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
@@ -1564,7 +1564,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
15641564
pub(crate) fn best_blame_constraint(
15651565
&self,
15661566
from_region: RegionVid,
1567-
from_region_origin: NllRegionVariableOrigin,
1567+
from_region_origin: NllRegionVariableOrigin<'tcx>,
15681568
to_region: RegionVid,
15691569
) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
15701570
assert!(from_region != to_region, "Trying to blame a region for itself!");

compiler/rustc_borrowck/src/region_infer/opaque_types/region_ctxt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(super) struct RegionCtxt<'a, 'tcx> {
2727
pub(super) constraint_sccs: ConstraintSccs,
2828
pub(super) scc_annotations: IndexVec<ConstraintSccIndex, RegionTracker>,
2929
pub(super) rev_scc_graph: ReverseSccGraph,
30-
pub(super) scc_values: RegionValues<ConstraintSccIndex>,
30+
pub(super) scc_values: RegionValues<'tcx, ConstraintSccIndex>,
3131
}
3232

3333
impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {

compiler/rustc_borrowck/src/region_infer/values.rs

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, RegionVid};
1010
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
1111
use tracing::debug;
1212

13-
use crate::BorrowIndex;
1413
use crate::polonius::LiveLoans;
14+
use crate::{BorrowIndex, TyCtxt};
1515

1616
rustc_index::newtype_index! {
1717
/// A single integer representing a `ty::Placeholder`.
@@ -22,7 +22,7 @@ rustc_index::newtype_index! {
2222
/// An individual element in a region value -- the value of a
2323
/// particular region variable consists of a set of these elements.
2424
#[derive(Debug, Clone, PartialEq)]
25-
pub(crate) enum RegionElement {
25+
pub(crate) enum RegionElement<'tcx> {
2626
/// A point in the control-flow graph.
2727
Location(Location),
2828

@@ -32,7 +32,7 @@ pub(crate) enum RegionElement {
3232

3333
/// A placeholder (e.g., instantiated from a `for<'a> fn(&'a u32)`
3434
/// type).
35-
PlaceholderRegion(ty::PlaceholderRegion),
35+
PlaceholderRegion(ty::PlaceholderRegion<'tcx>),
3636
}
3737

3838
/// Records the CFG locations where each region is live. When we initially compute liveness, we use
@@ -196,25 +196,28 @@ impl LivenessValues {
196196
/// NLL.
197197
#[derive(Debug, Default)]
198198
#[derive(Clone)] // FIXME(#146079)
199-
pub(crate) struct PlaceholderIndices {
200-
indices: FxIndexSet<ty::PlaceholderRegion>,
199+
pub(crate) struct PlaceholderIndices<'tcx> {
200+
indices: FxIndexSet<ty::PlaceholderRegion<'tcx>>,
201201
}
202202

203-
impl PlaceholderIndices {
203+
impl<'tcx> PlaceholderIndices<'tcx> {
204204
/// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion`
205-
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
205+
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion<'tcx>) -> PlaceholderIndex {
206206
let (index, _) = self.indices.insert_full(placeholder);
207207
index.into()
208208
}
209209

210-
pub(crate) fn lookup_index(&self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
210+
pub(crate) fn lookup_index(
211+
&self,
212+
placeholder: ty::PlaceholderRegion<'tcx>,
213+
) -> PlaceholderIndex {
211214
self.indices.get_index_of(&placeholder).unwrap().into()
212215
}
213216

214217
pub(crate) fn lookup_placeholder(
215218
&self,
216219
placeholder: PlaceholderIndex,
217-
) -> ty::PlaceholderRegion {
220+
) -> ty::PlaceholderRegion<'tcx> {
218221
self.indices[placeholder.index()]
219222
}
220223

@@ -241,9 +244,9 @@ impl PlaceholderIndices {
241244
/// Here, the variable `'0` would contain the free region `'a`,
242245
/// because (since it is returned) it must live for at least `'a`. But
243246
/// it would also contain various points from within the function.
244-
pub(crate) struct RegionValues<N: Idx> {
247+
pub(crate) struct RegionValues<'tcx, N: Idx> {
245248
location_map: Rc<DenseLocationMap>,
246-
placeholder_indices: PlaceholderIndices,
249+
placeholder_indices: PlaceholderIndices<'tcx>,
247250
points: SparseIntervalMatrix<N, PointIndex>,
248251
free_regions: SparseBitMatrix<N, RegionVid>,
249252

@@ -252,14 +255,14 @@ pub(crate) struct RegionValues<N: Idx> {
252255
placeholders: SparseBitMatrix<N, PlaceholderIndex>,
253256
}
254257

255-
impl<N: Idx> RegionValues<N> {
258+
impl<'tcx, N: Idx> RegionValues<'tcx, N> {
256259
/// Creates a new set of "region values" that tracks causal information.
257260
/// Each of the regions in num_region_variables will be initialized with an
258261
/// empty set of points and no causal information.
259262
pub(crate) fn new(
260263
location_map: Rc<DenseLocationMap>,
261264
num_universal_regions: usize,
262-
placeholder_indices: PlaceholderIndices,
265+
placeholder_indices: PlaceholderIndices<'tcx>,
263266
) -> Self {
264267
let num_points = location_map.num_points();
265268
let num_placeholders = placeholder_indices.len();
@@ -274,7 +277,7 @@ impl<N: Idx> RegionValues<N> {
274277

275278
/// Adds the given element to the value for the given region. Returns whether
276279
/// the element is newly added (i.e., was not already present).
277-
pub(crate) fn add_element(&mut self, r: N, elem: impl ToElementIndex) -> bool {
280+
pub(crate) fn add_element(&mut self, r: N, elem: impl ToElementIndex<'tcx>) -> bool {
278281
debug!("add(r={:?}, elem={:?})", r, elem);
279282
elem.add_to_row(self, r)
280283
}
@@ -293,7 +296,7 @@ impl<N: Idx> RegionValues<N> {
293296
}
294297

295298
/// Returns `true` if the region `r` contains the given element.
296-
pub(crate) fn contains(&self, r: N, elem: impl ToElementIndex) -> bool {
299+
pub(crate) fn contains(&self, r: N, elem: impl ToElementIndex<'tcx>) -> bool {
297300
elem.contained_in_row(self, r)
298301
}
299302

@@ -359,7 +362,7 @@ impl<N: Idx> RegionValues<N> {
359362
pub(crate) fn placeholders_contained_in(
360363
&self,
361364
r: N,
362-
) -> impl Iterator<Item = ty::PlaceholderRegion> {
365+
) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
363366
self.placeholders
364367
.row(r)
365368
.into_iter()
@@ -368,7 +371,7 @@ impl<N: Idx> RegionValues<N> {
368371
}
369372

370373
/// Returns all the elements contained in a given region's value.
371-
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement> {
374+
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement<'tcx>> {
372375
let points_iter = self.locations_outlived_by(r).map(RegionElement::Location);
373376

374377
let free_regions_iter =
@@ -386,42 +389,50 @@ impl<N: Idx> RegionValues<N> {
386389
}
387390
}
388391

389-
pub(crate) trait ToElementIndex: Debug + Copy {
390-
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool;
392+
pub(crate) trait ToElementIndex<'tcx>: Debug + Copy {
393+
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool;
391394

392-
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool;
395+
fn contained_in_row<N: Idx>(self, values: &RegionValues<'tcx, N>, row: N) -> bool;
393396
}
394397

395-
impl ToElementIndex for Location {
396-
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
398+
impl ToElementIndex<'_> for Location {
399+
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'_, N>, row: N) -> bool {
397400
let index = values.location_map.point_from_location(self);
398401
values.points.insert(row, index)
399402
}
400403

401-
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
404+
fn contained_in_row<N: Idx>(self, values: &RegionValues<'_, N>, row: N) -> bool {
402405
let index = values.location_map.point_from_location(self);
403406
values.points.contains(row, index)
404407
}
405408
}
406409

407-
impl ToElementIndex for RegionVid {
408-
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
410+
impl ToElementIndex<'_> for RegionVid {
411+
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'_, N>, row: N) -> bool {
409412
values.free_regions.insert(row, self)
410413
}
411414

412-
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
415+
fn contained_in_row<N: Idx>(self, values: &RegionValues<'_, N>, row: N) -> bool {
413416
values.free_regions.contains(row, self)
414417
}
415418
}
416419

417-
impl ToElementIndex for ty::PlaceholderRegion {
418-
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
419-
let index = values.placeholder_indices.lookup_index(self);
420+
impl<'tcx> ToElementIndex<'tcx> for ty::PlaceholderRegion<'tcx> {
421+
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool
422+
where
423+
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
424+
{
425+
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
426+
let index = values.placeholder_indices.lookup_index(placeholder);
420427
values.placeholders.insert(row, index)
421428
}
422429

423-
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
424-
let index = values.placeholder_indices.lookup_index(self);
430+
fn contained_in_row<N: Idx>(self, values: &RegionValues<'tcx, N>, row: N) -> bool
431+
where
432+
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
433+
{
434+
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
435+
let index = values.placeholder_indices.lookup_index(placeholder);
425436
values.placeholders.contains(row, index)
426437
}
427438
}
@@ -441,7 +452,9 @@ pub(crate) fn pretty_print_points(
441452
}
442453

443454
/// For debugging purposes, returns a pretty-printed string of the given region elements.
444-
fn pretty_print_region_elements(elements: impl IntoIterator<Item = RegionElement>) -> String {
455+
fn pretty_print_region_elements<'tcx>(
456+
elements: impl IntoIterator<Item = RegionElement<'tcx>>,
457+
) -> String {
445458
let mut result = String::new();
446459
result.push('{');
447460

0 commit comments

Comments
 (0)