Moved struct Placeholder<T>
This commit is contained in:
parent
03d7ad7dd6
commit
1986be2bcd
34 changed files with 326 additions and 251 deletions
|
|
@ -52,8 +52,8 @@ impl<'tcx> UniverseInfo<'tcx> {
|
|||
pub(crate) fn report_erroneous_element(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
error_element: RegionElement,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
error_element: RegionElement<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) {
|
||||
match *self {
|
||||
|
|
@ -152,8 +152,8 @@ pub(crate) trait TypeOpInfo<'tcx> {
|
|||
fn report_erroneous_element(
|
||||
&self,
|
||||
mbcx: &mut MirBorrowckCtxt<'_, '_, 'tcx>,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
error_element: RegionElement,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
error_element: RegionElement<'tcx>,
|
||||
cause: ObligationCause<'tcx>,
|
||||
) {
|
||||
let tcx = mbcx.infcx.tcx;
|
||||
|
|
@ -169,23 +169,22 @@ pub(crate) trait TypeOpInfo<'tcx> {
|
|||
|
||||
let placeholder_region = ty::Region::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
|
||||
ty::Placeholder::new(adjusted_universe.into(), placeholder.bound),
|
||||
);
|
||||
|
||||
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
|
||||
error_element
|
||||
{
|
||||
let adjusted_universe =
|
||||
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
||||
adjusted_universe.map(|adjusted| {
|
||||
ty::Region::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
|
||||
)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let error_region =
|
||||
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
|
||||
let adjusted_universe =
|
||||
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
|
||||
adjusted_universe.map(|adjusted| {
|
||||
ty::Region::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder::new(adjusted.into(), error_placeholder.bound),
|
||||
)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
debug!(?placeholder_region);
|
||||
|
||||
|
|
@ -440,7 +439,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
|
|||
placeholder_region: ty::Region<'tcx>,
|
||||
error_region: Option<ty::Region<'tcx>>,
|
||||
region_constraints: &RegionConstraintData<'tcx>,
|
||||
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
|
||||
mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin<'tcx>,
|
||||
mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
|
||||
) -> Option<Diag<'a>> {
|
||||
let placeholder_universe = match placeholder_region.kind() {
|
||||
|
|
|
|||
|
|
@ -109,15 +109,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
|
|||
/// The placeholder free region.
|
||||
longer_fr: RegionVid,
|
||||
/// The region element that erroneously must be outlived by `longer_fr`.
|
||||
error_element: RegionElement,
|
||||
error_element: RegionElement<'tcx>,
|
||||
/// The placeholder region.
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
},
|
||||
|
||||
/// Any other lifetime error.
|
||||
RegionError {
|
||||
/// The origin of the region.
|
||||
fr_origin: NllRegionVariableOrigin,
|
||||
fr_origin: NllRegionVariableOrigin<'tcx>,
|
||||
/// The region that should outlive `shorter_fr`.
|
||||
longer_fr: RegionVid,
|
||||
/// The region that should be shorter, but we can't prove it.
|
||||
|
|
@ -427,7 +427,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
|||
pub(crate) fn report_region_error(
|
||||
&mut self,
|
||||
fr: RegionVid,
|
||||
fr_origin: NllRegionVariableOrigin,
|
||||
fr_origin: NllRegionVariableOrigin<'tcx>,
|
||||
outlived_fr: RegionVid,
|
||||
outlives_suggestion: &mut OutlivesSuggestionBuilder,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ pub(crate) struct LoweredConstraints<'tcx> {
|
|||
pub(crate) type_tests: Vec<TypeTest<'tcx>>,
|
||||
pub(crate) liveness_constraints: LivenessValues,
|
||||
pub(crate) universe_causes: FxIndexMap<UniverseIndex, UniverseInfo<'tcx>>,
|
||||
pub(crate) placeholder_indices: PlaceholderIndices,
|
||||
pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
|
||||
}
|
||||
|
||||
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
|
||||
|
|
|
|||
|
|
@ -661,7 +661,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
|
|||
|
||||
pub(crate) fn next_region_var<F>(
|
||||
&self,
|
||||
origin: RegionVariableOrigin,
|
||||
origin: RegionVariableOrigin<'tcx>,
|
||||
get_ctxt_fn: F,
|
||||
) -> ty::Region<'tcx>
|
||||
where
|
||||
|
|
@ -683,7 +683,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
|
|||
#[instrument(skip(self, get_ctxt_fn), level = "debug")]
|
||||
pub(crate) fn next_nll_region_var<F>(
|
||||
&self,
|
||||
origin: NllRegionVariableOrigin,
|
||||
origin: NllRegionVariableOrigin<'tcx>,
|
||||
get_ctxt_fn: F,
|
||||
) -> ty::Region<'tcx>
|
||||
where
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ pub struct RegionInferenceContext<'tcx> {
|
|||
/// The final inferred values of the region variables; we compute
|
||||
/// one value per SCC. To get the value for any given *region*,
|
||||
/// you first find which scc it is a part of.
|
||||
scc_values: RegionValues<ConstraintSccIndex>,
|
||||
scc_values: RegionValues<'tcx, ConstraintSccIndex>,
|
||||
|
||||
/// Type constraints that we check after solving.
|
||||
type_tests: Vec<TypeTest<'tcx>>,
|
||||
|
|
@ -125,7 +125,7 @@ pub(crate) struct RegionDefinition<'tcx> {
|
|||
/// What kind of variable is this -- a free region? existential
|
||||
/// variable? etc. (See the `NllRegionVariableOrigin` for more
|
||||
/// info.)
|
||||
pub(crate) origin: NllRegionVariableOrigin,
|
||||
pub(crate) origin: NllRegionVariableOrigin<'tcx>,
|
||||
|
||||
/// Which universe is this region variable defined in? This is
|
||||
/// most often `ty::UniverseIndex::ROOT`, but when we encounter
|
||||
|
|
@ -453,7 +453,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
/// Returns `true` if the region `r` contains the point `p`.
|
||||
///
|
||||
/// Panics if called before `solve()` executes,
|
||||
pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex) -> bool {
|
||||
pub(crate) fn region_contains(&self, r: RegionVid, p: impl ToElementIndex<'tcx>) -> bool {
|
||||
let scc = self.constraint_sccs.scc(r);
|
||||
self.scc_values.contains(scc, p)
|
||||
}
|
||||
|
|
@ -481,7 +481,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
pub(crate) fn placeholders_contained_in(
|
||||
&self,
|
||||
r: RegionVid,
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> {
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
|
||||
let scc = self.constraint_sccs.scc(r);
|
||||
self.scc_values.placeholders_contained_in(scc)
|
||||
}
|
||||
|
|
@ -1311,7 +1311,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
fn check_bound_universal_region(
|
||||
&self,
|
||||
longer_fr: RegionVid,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
errors_buffer: &mut RegionErrors<'tcx>,
|
||||
) {
|
||||
debug!("check_bound_universal_region(fr={:?}, placeholder={:?})", longer_fr, placeholder,);
|
||||
|
|
@ -1523,7 +1523,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
pub(crate) fn region_from_element(
|
||||
&self,
|
||||
longer_fr: RegionVid,
|
||||
element: &RegionElement,
|
||||
element: &RegionElement<'tcx>,
|
||||
) -> RegionVid {
|
||||
match *element {
|
||||
RegionElement::Location(l) => self.find_sub_region_live_at(longer_fr, l),
|
||||
|
|
@ -1564,7 +1564,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
|||
pub(crate) fn best_blame_constraint(
|
||||
&self,
|
||||
from_region: RegionVid,
|
||||
from_region_origin: NllRegionVariableOrigin,
|
||||
from_region_origin: NllRegionVariableOrigin<'tcx>,
|
||||
to_region: RegionVid,
|
||||
) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
|
||||
assert!(from_region != to_region, "Trying to blame a region for itself!");
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub(super) struct RegionCtxt<'a, 'tcx> {
|
|||
pub(super) constraint_sccs: ConstraintSccs,
|
||||
pub(super) scc_annotations: IndexVec<ConstraintSccIndex, RegionTracker>,
|
||||
pub(super) rev_scc_graph: ReverseSccGraph,
|
||||
pub(super) scc_values: RegionValues<ConstraintSccIndex>,
|
||||
pub(super) scc_values: RegionValues<'tcx, ConstraintSccIndex>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ use rustc_middle::ty::{self, RegionVid};
|
|||
use rustc_mir_dataflow::points::{DenseLocationMap, PointIndex};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::BorrowIndex;
|
||||
use crate::polonius::LiveLoans;
|
||||
use crate::{BorrowIndex, TyCtxt};
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// A single integer representing a `ty::Placeholder`.
|
||||
|
|
@ -22,7 +22,7 @@ rustc_index::newtype_index! {
|
|||
/// An individual element in a region value -- the value of a
|
||||
/// particular region variable consists of a set of these elements.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub(crate) enum RegionElement {
|
||||
pub(crate) enum RegionElement<'tcx> {
|
||||
/// A point in the control-flow graph.
|
||||
Location(Location),
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ pub(crate) enum RegionElement {
|
|||
|
||||
/// A placeholder (e.g., instantiated from a `for<'a> fn(&'a u32)`
|
||||
/// type).
|
||||
PlaceholderRegion(ty::PlaceholderRegion),
|
||||
PlaceholderRegion(ty::PlaceholderRegion<'tcx>),
|
||||
}
|
||||
|
||||
/// Records the CFG locations where each region is live. When we initially compute liveness, we use
|
||||
|
|
@ -196,25 +196,28 @@ impl LivenessValues {
|
|||
/// NLL.
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Clone)] // FIXME(#146079)
|
||||
pub(crate) struct PlaceholderIndices {
|
||||
indices: FxIndexSet<ty::PlaceholderRegion>,
|
||||
pub(crate) struct PlaceholderIndices<'tcx> {
|
||||
indices: FxIndexSet<ty::PlaceholderRegion<'tcx>>,
|
||||
}
|
||||
|
||||
impl PlaceholderIndices {
|
||||
impl<'tcx> PlaceholderIndices<'tcx> {
|
||||
/// Returns the `PlaceholderIndex` for the inserted `PlaceholderRegion`
|
||||
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
|
||||
pub(crate) fn insert(&mut self, placeholder: ty::PlaceholderRegion<'tcx>) -> PlaceholderIndex {
|
||||
let (index, _) = self.indices.insert_full(placeholder);
|
||||
index.into()
|
||||
}
|
||||
|
||||
pub(crate) fn lookup_index(&self, placeholder: ty::PlaceholderRegion) -> PlaceholderIndex {
|
||||
pub(crate) fn lookup_index(
|
||||
&self,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
) -> PlaceholderIndex {
|
||||
self.indices.get_index_of(&placeholder).unwrap().into()
|
||||
}
|
||||
|
||||
pub(crate) fn lookup_placeholder(
|
||||
&self,
|
||||
placeholder: PlaceholderIndex,
|
||||
) -> ty::PlaceholderRegion {
|
||||
) -> ty::PlaceholderRegion<'tcx> {
|
||||
self.indices[placeholder.index()]
|
||||
}
|
||||
|
||||
|
|
@ -241,9 +244,9 @@ impl PlaceholderIndices {
|
|||
/// Here, the variable `'0` would contain the free region `'a`,
|
||||
/// because (since it is returned) it must live for at least `'a`. But
|
||||
/// it would also contain various points from within the function.
|
||||
pub(crate) struct RegionValues<N: Idx> {
|
||||
pub(crate) struct RegionValues<'tcx, N: Idx> {
|
||||
location_map: Rc<DenseLocationMap>,
|
||||
placeholder_indices: PlaceholderIndices,
|
||||
placeholder_indices: PlaceholderIndices<'tcx>,
|
||||
points: SparseIntervalMatrix<N, PointIndex>,
|
||||
free_regions: SparseBitMatrix<N, RegionVid>,
|
||||
|
||||
|
|
@ -252,14 +255,14 @@ pub(crate) struct RegionValues<N: Idx> {
|
|||
placeholders: SparseBitMatrix<N, PlaceholderIndex>,
|
||||
}
|
||||
|
||||
impl<N: Idx> RegionValues<N> {
|
||||
impl<'tcx, N: Idx> RegionValues<'tcx, N> {
|
||||
/// Creates a new set of "region values" that tracks causal information.
|
||||
/// Each of the regions in num_region_variables will be initialized with an
|
||||
/// empty set of points and no causal information.
|
||||
pub(crate) fn new(
|
||||
location_map: Rc<DenseLocationMap>,
|
||||
num_universal_regions: usize,
|
||||
placeholder_indices: PlaceholderIndices,
|
||||
placeholder_indices: PlaceholderIndices<'tcx>,
|
||||
) -> Self {
|
||||
let num_points = location_map.num_points();
|
||||
let num_placeholders = placeholder_indices.len();
|
||||
|
|
@ -274,7 +277,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
|
||||
/// Adds the given element to the value for the given region. Returns whether
|
||||
/// the element is newly added (i.e., was not already present).
|
||||
pub(crate) fn add_element(&mut self, r: N, elem: impl ToElementIndex) -> bool {
|
||||
pub(crate) fn add_element(&mut self, r: N, elem: impl ToElementIndex<'tcx>) -> bool {
|
||||
debug!("add(r={:?}, elem={:?})", r, elem);
|
||||
elem.add_to_row(self, r)
|
||||
}
|
||||
|
|
@ -293,7 +296,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
|
||||
/// Returns `true` if the region `r` contains the given element.
|
||||
pub(crate) fn contains(&self, r: N, elem: impl ToElementIndex) -> bool {
|
||||
pub(crate) fn contains(&self, r: N, elem: impl ToElementIndex<'tcx>) -> bool {
|
||||
elem.contained_in_row(self, r)
|
||||
}
|
||||
|
||||
|
|
@ -359,7 +362,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
pub(crate) fn placeholders_contained_in(
|
||||
&self,
|
||||
r: N,
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion> {
|
||||
) -> impl Iterator<Item = ty::PlaceholderRegion<'tcx>> {
|
||||
self.placeholders
|
||||
.row(r)
|
||||
.into_iter()
|
||||
|
|
@ -368,7 +371,7 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
|
||||
/// Returns all the elements contained in a given region's value.
|
||||
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement> {
|
||||
pub(crate) fn elements_contained_in(&self, r: N) -> impl Iterator<Item = RegionElement<'tcx>> {
|
||||
let points_iter = self.locations_outlived_by(r).map(RegionElement::Location);
|
||||
|
||||
let free_regions_iter =
|
||||
|
|
@ -386,42 +389,50 @@ impl<N: Idx> RegionValues<N> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) trait ToElementIndex: Debug + Copy {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool;
|
||||
pub(crate) trait ToElementIndex<'tcx>: Debug + Copy {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool;
|
||||
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool;
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<'tcx, N>, row: N) -> bool;
|
||||
}
|
||||
|
||||
impl ToElementIndex for Location {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
|
||||
impl ToElementIndex<'_> for Location {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'_, N>, row: N) -> bool {
|
||||
let index = values.location_map.point_from_location(self);
|
||||
values.points.insert(row, index)
|
||||
}
|
||||
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<'_, N>, row: N) -> bool {
|
||||
let index = values.location_map.point_from_location(self);
|
||||
values.points.contains(row, index)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToElementIndex for RegionVid {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
|
||||
impl ToElementIndex<'_> for RegionVid {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'_, N>, row: N) -> bool {
|
||||
values.free_regions.insert(row, self)
|
||||
}
|
||||
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<'_, N>, row: N) -> bool {
|
||||
values.free_regions.contains(row, self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToElementIndex for ty::PlaceholderRegion {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<N>, row: N) -> bool {
|
||||
let index = values.placeholder_indices.lookup_index(self);
|
||||
impl<'tcx> ToElementIndex<'tcx> for ty::PlaceholderRegion<'tcx> {
|
||||
fn add_to_row<N: Idx>(self, values: &mut RegionValues<'tcx, N>, row: N) -> bool
|
||||
where
|
||||
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
|
||||
{
|
||||
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
|
||||
let index = values.placeholder_indices.lookup_index(placeholder);
|
||||
values.placeholders.insert(row, index)
|
||||
}
|
||||
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<N>, row: N) -> bool {
|
||||
let index = values.placeholder_indices.lookup_index(self);
|
||||
fn contained_in_row<N: Idx>(self, values: &RegionValues<'tcx, N>, row: N) -> bool
|
||||
where
|
||||
Self: Into<ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion>>,
|
||||
{
|
||||
let placeholder: ty::Placeholder<TyCtxt<'tcx>, ty::BoundRegion> = self.into();
|
||||
let index = values.placeholder_indices.lookup_index(placeholder);
|
||||
values.placeholders.contains(row, index)
|
||||
}
|
||||
}
|
||||
|
|
@ -441,7 +452,9 @@ pub(crate) fn pretty_print_points(
|
|||
}
|
||||
|
||||
/// For debugging purposes, returns a pretty-printed string of the given region elements.
|
||||
fn pretty_print_region_elements(elements: impl IntoIterator<Item = RegionElement>) -> String {
|
||||
fn pretty_print_region_elements<'tcx>(
|
||||
elements: impl IntoIterator<Item = RegionElement<'tcx>>,
|
||||
) -> String {
|
||||
let mut result = String::new();
|
||||
result.push('{');
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,7 @@ pub(crate) struct MirTypeckRegionConstraints<'tcx> {
|
|||
///
|
||||
/// To keep everything in sync, do not insert this set
|
||||
/// directly. Instead, use the `placeholder_region` helper.
|
||||
pub(crate) placeholder_indices: PlaceholderIndices,
|
||||
pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
|
||||
|
||||
/// Each time we add a placeholder to `placeholder_indices`, we
|
||||
/// also create a corresponding "representative" region vid for
|
||||
|
|
@ -289,7 +289,7 @@ impl<'tcx> MirTypeckRegionConstraints<'tcx> {
|
|||
pub(crate) fn placeholder_region(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
) -> ty::Region<'tcx> {
|
||||
let placeholder_index = self.placeholder_indices.insert(placeholder);
|
||||
match self.placeholder_index_to_region.get(placeholder_index) {
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
|
|||
universe
|
||||
});
|
||||
|
||||
let placeholder = ty::PlaceholderRegion { universe, bound: br };
|
||||
let placeholder = ty::PlaceholderRegion::new(universe, br);
|
||||
debug!(?placeholder);
|
||||
let placeholder_reg = self.next_placeholder_region(placeholder);
|
||||
debug!(?placeholder_reg);
|
||||
|
|
@ -257,7 +257,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> {
|
|||
}
|
||||
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
|
||||
fn next_placeholder_region(
|
||||
&mut self,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
) -> ty::Region<'tcx> {
|
||||
let reg =
|
||||
self.type_checker.constraints.placeholder_region(self.type_checker.infcx, placeholder);
|
||||
|
||||
|
|
|
|||
|
|
@ -454,8 +454,6 @@ struct UniversalRegionsBuilder<'infcx, 'tcx> {
|
|||
mir_def: LocalDefId,
|
||||
}
|
||||
|
||||
const FR: NllRegionVariableOrigin = NllRegionVariableOrigin::FreeRegion;
|
||||
|
||||
impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
||||
fn build(self) -> UniversalRegions<'tcx> {
|
||||
debug!("build(mir_def={:?})", self.mir_def);
|
||||
|
|
@ -466,8 +464,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());
|
||||
|
||||
// Create the "global" region that is always free in all contexts: 'static.
|
||||
let fr_static =
|
||||
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).as_var();
|
||||
let fr_static = self
|
||||
.infcx
|
||||
.next_nll_region_var(NllRegionVariableOrigin::FreeRegion, || {
|
||||
RegionCtxt::Free(kw::Static)
|
||||
})
|
||||
.as_var();
|
||||
|
||||
// We've now added all the global regions. The next ones we
|
||||
// add will be external.
|
||||
|
|
@ -500,7 +502,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
debug!(?r);
|
||||
let region_vid = {
|
||||
let name = r.get_name_or_anon(self.infcx.tcx);
|
||||
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
|
||||
self.infcx.next_nll_region_var(NllRegionVariableOrigin::FreeRegion, || {
|
||||
RegionCtxt::LateBound(name)
|
||||
})
|
||||
};
|
||||
|
||||
debug!(?region_vid);
|
||||
|
|
@ -526,7 +530,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
let r = ty::Region::new_late_param(self.infcx.tcx, self.mir_def.to_def_id(), kind);
|
||||
let region_vid = {
|
||||
let name = r.get_name_or_anon(self.infcx.tcx);
|
||||
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
|
||||
self.infcx.next_nll_region_var(NllRegionVariableOrigin::FreeRegion, || {
|
||||
RegionCtxt::LateBound(name)
|
||||
})
|
||||
};
|
||||
|
||||
debug!(?region_vid);
|
||||
|
|
@ -553,7 +559,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
|
||||
let reg_vid = self
|
||||
.infcx
|
||||
.next_nll_region_var(FR, || RegionCtxt::Free(sym::c_dash_variadic))
|
||||
.next_nll_region_var(NllRegionVariableOrigin::FreeRegion, || {
|
||||
RegionCtxt::Free(sym::c_dash_variadic)
|
||||
})
|
||||
.as_var();
|
||||
|
||||
let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
|
||||
|
|
@ -569,8 +577,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
let fr_fn_body =
|
||||
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(sym::fn_body)).as_var();
|
||||
let fr_fn_body = self
|
||||
.infcx
|
||||
.next_nll_region_var(NllRegionVariableOrigin::FreeRegion, || {
|
||||
RegionCtxt::Free(sym::fn_body)
|
||||
})
|
||||
.as_var();
|
||||
|
||||
let num_universals = self.infcx.num_region_vars();
|
||||
|
||||
|
|
@ -613,8 +625,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
|
||||
debug!("defining_ty (pre-replacement): {:?}", defining_ty);
|
||||
|
||||
let defining_ty =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty);
|
||||
let defining_ty = self.infcx.replace_free_regions_with_nll_infer_vars(
|
||||
NllRegionVariableOrigin::FreeRegion,
|
||||
defining_ty,
|
||||
);
|
||||
|
||||
match *defining_ty.kind() {
|
||||
ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args),
|
||||
|
|
@ -638,8 +652,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
// Do not ICE when checking default_field_values consts with lifetimes (#135649)
|
||||
&& DefKind::Field != tcx.def_kind(tcx.parent(typeck_root_def_id))
|
||||
{
|
||||
let args =
|
||||
self.infcx.replace_free_regions_with_nll_infer_vars(FR, identity_args);
|
||||
let args = self.infcx.replace_free_regions_with_nll_infer_vars(
|
||||
NllRegionVariableOrigin::FreeRegion,
|
||||
identity_args,
|
||||
);
|
||||
DefiningTy::Const(self.mir_def.to_def_id(), args)
|
||||
} else {
|
||||
// FIXME this line creates a dependency between borrowck and typeck.
|
||||
|
|
@ -659,7 +675,10 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
|
|||
InlineConstArgsParts { parent_args: identity_args, ty },
|
||||
)
|
||||
.args;
|
||||
let args = self.infcx.replace_free_regions_with_nll_infer_vars(FR, args);
|
||||
let args = self.infcx.replace_free_regions_with_nll_infer_vars(
|
||||
NllRegionVariableOrigin::FreeRegion,
|
||||
args,
|
||||
);
|
||||
DefiningTy::InlineConst(self.mir_def.to_def_id(), args)
|
||||
}
|
||||
}
|
||||
|
|
@ -856,7 +875,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
|
|||
#[instrument(skip(self), level = "debug")]
|
||||
fn replace_free_regions_with_nll_infer_vars<T>(
|
||||
&self,
|
||||
origin: NllRegionVariableOrigin,
|
||||
origin: NllRegionVariableOrigin<'tcx>,
|
||||
value: T,
|
||||
) -> T
|
||||
where
|
||||
|
|
|
|||
|
|
@ -590,10 +590,10 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
|
|||
ty,
|
||||
Ty::new_placeholder(
|
||||
tcx,
|
||||
ty::Placeholder {
|
||||
ty::Placeholder::new(
|
||||
universe,
|
||||
bound: ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
|
||||
},
|
||||
ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
|
||||
),
|
||||
),
|
||||
)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -684,22 +684,22 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
|
|||
CanonicalVarKind::Region(u) => CanonicalVarKind::Region(reverse_universe_map[&u]),
|
||||
CanonicalVarKind::Const(u) => CanonicalVarKind::Const(reverse_universe_map[&u]),
|
||||
CanonicalVarKind::PlaceholderTy(placeholder) => {
|
||||
CanonicalVarKind::PlaceholderTy(ty::Placeholder {
|
||||
universe: reverse_universe_map[&placeholder.universe],
|
||||
..placeholder
|
||||
})
|
||||
CanonicalVarKind::PlaceholderTy(ty::Placeholder::new(
|
||||
reverse_universe_map[&placeholder.universe],
|
||||
placeholder.bound,
|
||||
))
|
||||
}
|
||||
CanonicalVarKind::PlaceholderRegion(placeholder) => {
|
||||
CanonicalVarKind::PlaceholderRegion(ty::Placeholder {
|
||||
universe: reverse_universe_map[&placeholder.universe],
|
||||
..placeholder
|
||||
})
|
||||
CanonicalVarKind::PlaceholderRegion(ty::Placeholder::new(
|
||||
reverse_universe_map[&placeholder.universe],
|
||||
placeholder.bound,
|
||||
))
|
||||
}
|
||||
CanonicalVarKind::PlaceholderConst(placeholder) => {
|
||||
CanonicalVarKind::PlaceholderConst(ty::Placeholder {
|
||||
universe: reverse_universe_map[&placeholder.universe],
|
||||
..placeholder
|
||||
})
|
||||
CanonicalVarKind::PlaceholderConst(ty::Placeholder::new(
|
||||
reverse_universe_map[&placeholder.universe],
|
||||
placeholder.bound,
|
||||
))
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
CanonicalVarKind::Float => self.next_float_var().into(),
|
||||
|
||||
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound }) => {
|
||||
CanonicalVarKind::PlaceholderTy(ty::PlaceholderType { universe, bound, .. }) => {
|
||||
let universe_mapped = universe_map(universe);
|
||||
let placeholder_mapped = ty::PlaceholderType { universe: universe_mapped, bound };
|
||||
let placeholder_mapped = ty::PlaceholderType::new(universe_mapped, bound);
|
||||
Ty::new_placeholder(self.tcx, placeholder_mapped).into()
|
||||
}
|
||||
|
||||
|
|
@ -119,18 +119,22 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
.next_region_var_in_universe(RegionVariableOrigin::Misc(span), universe_map(ui))
|
||||
.into(),
|
||||
|
||||
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion { universe, bound }) => {
|
||||
CanonicalVarKind::PlaceholderRegion(ty::PlaceholderRegion {
|
||||
universe, bound, ..
|
||||
}) => {
|
||||
let universe_mapped = universe_map(universe);
|
||||
let placeholder_mapped = ty::PlaceholderRegion { universe: universe_mapped, bound };
|
||||
let placeholder_mapped = ty::PlaceholderRegion::new(universe_mapped, bound);
|
||||
ty::Region::new_placeholder(self.tcx, placeholder_mapped).into()
|
||||
}
|
||||
|
||||
CanonicalVarKind::Const(ui) => {
|
||||
self.next_const_var_in_universe(span, universe_map(ui)).into()
|
||||
}
|
||||
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, bound }) => {
|
||||
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst {
|
||||
universe, bound, ..
|
||||
}) => {
|
||||
let universe_mapped = universe_map(universe);
|
||||
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, bound };
|
||||
let placeholder_mapped = ty::PlaceholderConst::new(universe_mapped, bound);
|
||||
ty::Const::new_placeholder(self.tcx, placeholder_mapped).into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ use crate::infer::{RegionRelations, RegionVariableOrigin, SubregionOrigin};
|
|||
#[instrument(level = "debug", skip(region_rels, var_infos, data))]
|
||||
pub(crate) fn resolve<'tcx>(
|
||||
region_rels: &RegionRelations<'_, 'tcx>,
|
||||
var_infos: VarInfos,
|
||||
var_infos: VarInfos<'tcx>,
|
||||
data: RegionConstraintData<'tcx>,
|
||||
) -> (LexicalRegionResolutions<'tcx>, Vec<RegionResolutionError<'tcx>>) {
|
||||
let mut errors = vec![];
|
||||
|
|
@ -80,7 +80,7 @@ pub enum RegionResolutionError<'tcx> {
|
|||
/// `sub_r <= sup_r` does not hold.
|
||||
SubSupConflict(
|
||||
RegionVid,
|
||||
RegionVariableOrigin,
|
||||
RegionVariableOrigin<'tcx>,
|
||||
SubregionOrigin<'tcx>,
|
||||
Region<'tcx>,
|
||||
SubregionOrigin<'tcx>,
|
||||
|
|
@ -92,7 +92,7 @@ pub enum RegionResolutionError<'tcx> {
|
|||
/// cannot name the placeholder `'b`.
|
||||
UpperBoundUniverseConflict(
|
||||
RegionVid,
|
||||
RegionVariableOrigin,
|
||||
RegionVariableOrigin<'tcx>,
|
||||
ty::UniverseIndex, // the universe index of the region variable
|
||||
SubregionOrigin<'tcx>, // cause of the constraint
|
||||
Region<'tcx>, // the placeholder `'b`
|
||||
|
|
@ -122,7 +122,7 @@ type RegionGraph<'tcx> = LinkedGraph<(), Constraint<'tcx>>;
|
|||
|
||||
struct LexicalResolver<'cx, 'tcx> {
|
||||
region_rels: &'cx RegionRelations<'cx, 'tcx>,
|
||||
var_infos: VarInfos,
|
||||
var_infos: VarInfos<'tcx>,
|
||||
data: RegionConstraintData<'tcx>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -421,7 +421,7 @@ pub enum BoundRegionConversionTime {
|
|||
///
|
||||
/// See `error_reporting` module for more details.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum RegionVariableOrigin {
|
||||
pub enum RegionVariableOrigin<'tcx> {
|
||||
/// Region variables created for ill-categorized reasons.
|
||||
///
|
||||
/// They mostly indicate places in need of refactoring.
|
||||
|
|
@ -453,11 +453,11 @@ pub enum RegionVariableOrigin {
|
|||
|
||||
/// This origin is used for the inference variables that we create
|
||||
/// during NLL region processing.
|
||||
Nll(NllRegionVariableOrigin),
|
||||
Nll(NllRegionVariableOrigin<'tcx>),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum NllRegionVariableOrigin {
|
||||
pub enum NllRegionVariableOrigin<'tcx> {
|
||||
/// During NLL region processing, we create variables for free
|
||||
/// regions that we encounter in the function signature and
|
||||
/// elsewhere. This origin indices we've got one of those.
|
||||
|
|
@ -465,7 +465,7 @@ pub enum NllRegionVariableOrigin {
|
|||
|
||||
/// "Universal" instantiation of a higher-ranked region (e.g.,
|
||||
/// from a `for<'a> T` binder). Meant to represent "any region".
|
||||
Placeholder(ty::PlaceholderRegion),
|
||||
Placeholder(ty::PlaceholderRegion<'tcx>),
|
||||
|
||||
Existential {
|
||||
name: Option<Symbol>,
|
||||
|
|
@ -838,7 +838,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
/// Creates a fresh region variable with the next available index.
|
||||
/// The variable will be created in the maximum universe created
|
||||
/// thus far, allowing it to name any region created thus far.
|
||||
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region<'tcx> {
|
||||
pub fn next_region_var(&self, origin: RegionVariableOrigin<'tcx>) -> ty::Region<'tcx> {
|
||||
self.next_region_var_in_universe(origin, self.universe())
|
||||
}
|
||||
|
||||
|
|
@ -847,7 +847,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
/// `next_region_var` and just use the maximal universe.
|
||||
pub fn next_region_var_in_universe(
|
||||
&self,
|
||||
origin: RegionVariableOrigin,
|
||||
origin: RegionVariableOrigin<'tcx>,
|
||||
universe: ty::UniverseIndex,
|
||||
) -> ty::Region<'tcx> {
|
||||
let region_var =
|
||||
|
|
@ -878,7 +878,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
/// Just a convenient wrapper of `next_region_var` for using during NLL.
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn next_nll_region_var(&self, origin: NllRegionVariableOrigin) -> ty::Region<'tcx> {
|
||||
pub fn next_nll_region_var(&self, origin: NllRegionVariableOrigin<'tcx>) -> ty::Region<'tcx> {
|
||||
self.next_region_var(RegionVariableOrigin::Nll(origin))
|
||||
}
|
||||
|
||||
|
|
@ -886,7 +886,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
#[instrument(skip(self), level = "debug")]
|
||||
pub fn next_nll_region_var_in_universe(
|
||||
&self,
|
||||
origin: NllRegionVariableOrigin,
|
||||
origin: NllRegionVariableOrigin<'tcx>,
|
||||
universe: ty::UniverseIndex,
|
||||
) -> ty::Region<'tcx> {
|
||||
self.next_region_var_in_universe(RegionVariableOrigin::Nll(origin), universe)
|
||||
|
|
@ -954,7 +954,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
self.tainted_by_errors.set(Some(e));
|
||||
}
|
||||
|
||||
pub fn region_var_origin(&self, vid: ty::RegionVid) -> RegionVariableOrigin {
|
||||
pub fn region_var_origin(&self, vid: ty::RegionVid) -> RegionVariableOrigin<'tcx> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let inner = &mut *inner;
|
||||
inner.unwrap_region_constraints().var_origin(vid)
|
||||
|
|
@ -962,7 +962,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
/// Clone the list of variable regions. This is used only during NLL processing
|
||||
/// to put the set of region variables into the NLL region context.
|
||||
pub fn get_region_var_infos(&self) -> VarInfos {
|
||||
pub fn get_region_var_infos(&self) -> VarInfos<'tcx> {
|
||||
let inner = self.inner.borrow();
|
||||
assert!(!UndoLogs::<UndoLog<'_>>::in_snapshot(&inner.undo_log));
|
||||
let storage = inner.region_constraint_storage.as_ref().expect("regions already resolved");
|
||||
|
|
@ -1649,7 +1649,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl RegionVariableOrigin {
|
||||
impl<'tcx> RegionVariableOrigin<'tcx> {
|
||||
pub fn span(&self) -> Span {
|
||||
match *self {
|
||||
RegionVariableOrigin::Misc(a)
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ where
|
|||
&mut self,
|
||||
origin: infer::SubregionOrigin<'tcx>,
|
||||
region: ty::Region<'tcx>,
|
||||
placeholder_ty: ty::PlaceholderType,
|
||||
placeholder_ty: ty::PlaceholderType<'tcx>,
|
||||
) {
|
||||
let verify_bound = self
|
||||
.verify_bound
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ struct LeakCheck<'a, 'tcx> {
|
|||
// is repurposed to store some placeholder `P` such that the weaker
|
||||
// condition `S: P` must hold. (This is true if `S: S1` transitively and `S1
|
||||
// = P`.)
|
||||
scc_placeholders: IndexVec<LeakCheckScc, Option<ty::PlaceholderRegion>>,
|
||||
scc_placeholders: IndexVec<LeakCheckScc, Option<ty::PlaceholderRegion<'tcx>>>,
|
||||
|
||||
// For each SCC S, track the minimum universe that flows into it. Note that
|
||||
// this is both the minimum of the universes for every region that is a
|
||||
|
|
@ -258,15 +258,15 @@ impl<'a, 'tcx> LeakCheck<'a, 'tcx> {
|
|||
|
||||
fn placeholder_error(
|
||||
&self,
|
||||
placeholder1: ty::PlaceholderRegion,
|
||||
placeholder2: ty::PlaceholderRegion,
|
||||
placeholder1: ty::PlaceholderRegion<'tcx>,
|
||||
placeholder2: ty::PlaceholderRegion<'tcx>,
|
||||
) -> TypeError<'tcx> {
|
||||
self.error(placeholder1, ty::Region::new_placeholder(self.tcx, placeholder2))
|
||||
}
|
||||
|
||||
fn error(
|
||||
&self,
|
||||
placeholder: ty::PlaceholderRegion,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
other_region: ty::Region<'tcx>,
|
||||
) -> TypeError<'tcx> {
|
||||
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ mod leak_check;
|
|||
#[derive(Clone, Default)]
|
||||
pub struct RegionConstraintStorage<'tcx> {
|
||||
/// For each `RegionVid`, the corresponding `RegionVariableOrigin`.
|
||||
pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo>,
|
||||
pub(super) var_infos: IndexVec<RegionVid, RegionVariableInfo<'tcx>>,
|
||||
|
||||
pub(super) data: RegionConstraintData<'tcx>,
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ pub struct RegionConstraintCollector<'a, 'tcx> {
|
|||
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
|
||||
}
|
||||
|
||||
pub type VarInfos = IndexVec<RegionVid, RegionVariableInfo>;
|
||||
pub type VarInfos<'tcx> = IndexVec<RegionVid, RegionVariableInfo<'tcx>>;
|
||||
|
||||
/// The full set of region constraints gathered up by the collector.
|
||||
/// Describes constraints between the region variables and other
|
||||
|
|
@ -125,7 +125,7 @@ pub struct Verify<'tcx> {
|
|||
#[derive(Copy, Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)]
|
||||
pub enum GenericKind<'tcx> {
|
||||
Param(ty::ParamTy),
|
||||
Placeholder(ty::PlaceholderType),
|
||||
Placeholder(ty::PlaceholderType<'tcx>),
|
||||
Alias(ty::AliasTy<'tcx>),
|
||||
}
|
||||
|
||||
|
|
@ -269,8 +269,8 @@ pub(crate) enum CombineMapType {
|
|||
type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct RegionVariableInfo {
|
||||
pub origin: RegionVariableOrigin,
|
||||
pub struct RegionVariableInfo<'tcx> {
|
||||
pub origin: RegionVariableOrigin<'tcx>,
|
||||
// FIXME: This is only necessary for `fn take_and_reset_data` and
|
||||
// `lexical_region_resolve`. We should rework `lexical_region_resolve`
|
||||
// in the near/medium future anyways and could move the unverse info
|
||||
|
|
@ -374,7 +374,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
pub(super) fn new_region_var(
|
||||
&mut self,
|
||||
universe: ty::UniverseIndex,
|
||||
origin: RegionVariableOrigin,
|
||||
origin: RegionVariableOrigin<'tcx>,
|
||||
) -> RegionVid {
|
||||
let vid = self.storage.var_infos.push(RegionVariableInfo { origin, universe });
|
||||
|
||||
|
|
@ -386,7 +386,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
}
|
||||
|
||||
/// Returns the origin for the given variable.
|
||||
pub(super) fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin {
|
||||
pub(super) fn var_origin(&self, vid: RegionVid) -> RegionVariableOrigin<'tcx> {
|
||||
self.storage.var_infos[vid].origin
|
||||
}
|
||||
|
||||
|
|
@ -624,10 +624,10 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn vars_since_snapshot(
|
||||
&self,
|
||||
pub fn vars_since_snapshot<'a>(
|
||||
&'a self,
|
||||
value_count: usize,
|
||||
) -> (Range<RegionVid>, Vec<RegionVariableOrigin>) {
|
||||
) -> (Range<RegionVid>, Vec<RegionVariableOrigin<'tcx>>) {
|
||||
let range =
|
||||
RegionVid::from(value_count)..RegionVid::from(self.storage.unification_table.len());
|
||||
(
|
||||
|
|
|
|||
|
|
@ -34,21 +34,15 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
let delegate = FnMutDelegate {
|
||||
regions: &mut |br: ty::BoundRegion| {
|
||||
ty::Region::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderRegion { universe: next_universe, bound: br },
|
||||
)
|
||||
ty::Region::new_placeholder(self.tcx, ty::PlaceholderRegion::new(next_universe, br))
|
||||
},
|
||||
types: &mut |bound_ty: ty::BoundTy| {
|
||||
Ty::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderType { universe: next_universe, bound: bound_ty },
|
||||
)
|
||||
Ty::new_placeholder(self.tcx, ty::PlaceholderType::new(next_universe, bound_ty))
|
||||
},
|
||||
consts: &mut |bound_const: ty::BoundConst| {
|
||||
ty::Const::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderConst { universe: next_universe, bound: bound_const },
|
||||
ty::PlaceholderConst::new(next_universe, bound_const),
|
||||
)
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
|
||||
fn fudge_inference<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
&self,
|
||||
snapshot_vars: SnapshotVarData,
|
||||
snapshot_vars: SnapshotVarData<'tcx>,
|
||||
value: T,
|
||||
) -> T {
|
||||
// Micro-optimization: if no variables have been created, then
|
||||
|
|
@ -126,16 +126,16 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
struct SnapshotVarData {
|
||||
region_vars: (Range<RegionVid>, Vec<RegionVariableOrigin>),
|
||||
struct SnapshotVarData<'tcx> {
|
||||
region_vars: (Range<RegionVid>, Vec<RegionVariableOrigin<'tcx>>),
|
||||
type_vars: (Range<TyVid>, Vec<TypeVariableOrigin>),
|
||||
int_vars: Range<IntVid>,
|
||||
float_vars: Range<FloatVid>,
|
||||
const_vars: (Range<ConstVid>, Vec<ConstVariableOrigin>),
|
||||
}
|
||||
|
||||
impl SnapshotVarData {
|
||||
fn new(infcx: &InferCtxt<'_>, vars_pre_snapshot: VariableLengths) -> SnapshotVarData {
|
||||
impl<'tcx> SnapshotVarData<'tcx> {
|
||||
fn new(infcx: &InferCtxt<'tcx>, vars_pre_snapshot: VariableLengths) -> SnapshotVarData<'tcx> {
|
||||
let mut inner = infcx.inner.borrow_mut();
|
||||
let region_vars = inner
|
||||
.unwrap_region_constraints()
|
||||
|
|
@ -165,7 +165,7 @@ impl SnapshotVarData {
|
|||
|
||||
struct InferenceFudger<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
snapshot_vars: SnapshotVarData,
|
||||
snapshot_vars: SnapshotVarData<'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,10 @@ impl<'tcx> Const<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst) -> Const<'tcx> {
|
||||
pub fn new_placeholder(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
placeholder: ty::PlaceholderConst<'tcx>,
|
||||
) -> Const<'tcx> {
|
||||
Const::new(tcx, ty::ConstKind::Placeholder(placeholder))
|
||||
}
|
||||
|
||||
|
|
@ -192,7 +195,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
|
|||
Const::new_canonical_bound(tcx, var)
|
||||
}
|
||||
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst) -> Self {
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<'tcx>) -> Self {
|
||||
Const::new_placeholder(tcx, placeholder)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
type BoundTy = ty::BoundTy;
|
||||
type Symbol = Symbol;
|
||||
|
||||
type PlaceholderTy = ty::PlaceholderType;
|
||||
type PlaceholderTy = ty::PlaceholderType<'tcx>;
|
||||
type ErrorGuaranteed = ErrorGuaranteed;
|
||||
type BoundExistentialPredicates = &'tcx List<PolyExistentialPredicate<'tcx>>;
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
type Safety = hir::Safety;
|
||||
type Abi = ExternAbi;
|
||||
type Const = ty::Const<'tcx>;
|
||||
type PlaceholderConst = ty::PlaceholderConst;
|
||||
type PlaceholderConst = ty::PlaceholderConst<'tcx>;
|
||||
|
||||
type ParamConst = ty::ParamConst;
|
||||
type BoundConst = ty::BoundConst;
|
||||
|
|
@ -170,7 +170,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
type EarlyParamRegion = ty::EarlyParamRegion;
|
||||
type LateParamRegion = ty::LateParamRegion;
|
||||
type BoundRegion = ty::BoundRegion;
|
||||
type PlaceholderRegion = ty::PlaceholderRegion;
|
||||
type PlaceholderRegion = ty::PlaceholderRegion<'tcx>;
|
||||
|
||||
type RegionAssumptions = &'tcx ty::List<ty::ArgOutlivesPredicate<'tcx>>;
|
||||
|
||||
|
|
|
|||
|
|
@ -886,20 +886,9 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
|
||||
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
|
||||
/// regions/types/consts within the same universe simply have an unknown relationship to one
|
||||
/// another.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[derive(HashStable, TyEncodable, TyDecodable)]
|
||||
pub struct Placeholder<T> {
|
||||
pub universe: UniverseIndex,
|
||||
pub bound: T,
|
||||
}
|
||||
pub type PlaceholderRegion<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundRegion>;
|
||||
|
||||
pub type PlaceholderRegion = Placeholder<BoundRegion>;
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderRegion {
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderRegion<'tcx> {
|
||||
type Bound = BoundRegion;
|
||||
|
||||
fn universe(self) -> UniverseIndex {
|
||||
|
|
@ -911,21 +900,21 @@ impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for Placeholde
|
|||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
ty::Placeholder::new(ui, self.bound)
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, bound: BoundRegion) -> Self {
|
||||
Placeholder { universe: ui, bound }
|
||||
ty::Placeholder::new(ui, bound)
|
||||
}
|
||||
|
||||
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::Anon } }
|
||||
ty::Placeholder::new(ui, BoundRegion { var, kind: BoundRegionKind::Anon })
|
||||
}
|
||||
}
|
||||
|
||||
pub type PlaceholderType = Placeholder<BoundTy>;
|
||||
pub type PlaceholderType<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundTy>;
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderType {
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderType<'tcx> {
|
||||
type Bound = BoundTy;
|
||||
|
||||
fn universe(self) -> UniverseIndex {
|
||||
|
|
@ -937,15 +926,15 @@ impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for Placeholde
|
|||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
ty::Placeholder::new(ui, self.bound)
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, bound: BoundTy) -> Self {
|
||||
Placeholder { universe: ui, bound }
|
||||
ty::Placeholder::new(ui, bound)
|
||||
}
|
||||
|
||||
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundTy { var, kind: BoundTyKind::Anon } }
|
||||
ty::Placeholder::new(ui, BoundTy { var, kind: BoundTyKind::Anon })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -965,9 +954,9 @@ impl<'tcx> rustc_type_ir::inherent::BoundVarLike<TyCtxt<'tcx>> for BoundConst {
|
|||
}
|
||||
}
|
||||
|
||||
pub type PlaceholderConst = Placeholder<BoundConst>;
|
||||
pub type PlaceholderConst<'tcx> = ty::Placeholder<TyCtxt<'tcx>, BoundConst>;
|
||||
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderConst {
|
||||
impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for PlaceholderConst<'tcx> {
|
||||
type Bound = BoundConst;
|
||||
|
||||
fn universe(self) -> UniverseIndex {
|
||||
|
|
@ -979,15 +968,15 @@ impl<'tcx> rustc_type_ir::inherent::PlaceholderLike<TyCtxt<'tcx>> for Placeholde
|
|||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
ty::Placeholder::new(ui, self.bound)
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, bound: BoundConst) -> Self {
|
||||
Placeholder { universe: ui, bound }
|
||||
ty::Placeholder::new(ui, bound)
|
||||
}
|
||||
|
||||
fn new_anon(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundConst { var } }
|
||||
ty::Placeholder::new(ui, BoundConst { var })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3274,6 +3274,16 @@ define_print! {
|
|||
p.reset_type_limit();
|
||||
self.term.print(p)?;
|
||||
}
|
||||
|
||||
ty::PlaceholderType<'tcx> {
|
||||
match self.bound.kind {
|
||||
ty::BoundTyKind::Anon => write!(p, "{self:?}")?,
|
||||
ty::BoundTyKind::Param(def_id) => match p.should_print_verbose() {
|
||||
true => write!(p, "{self:?}")?,
|
||||
false => write!(p, "{}", p.tcx().item_name(def_id))?,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
define_print_and_forward_display! {
|
||||
|
|
@ -3338,16 +3348,6 @@ define_print_and_forward_display! {
|
|||
write!(p, "{}", self.name)?;
|
||||
}
|
||||
|
||||
ty::PlaceholderType {
|
||||
match self.bound.kind {
|
||||
ty::BoundTyKind::Anon => write!(p, "{self:?}")?,
|
||||
ty::BoundTyKind::Param(def_id) => match p.should_print_verbose() {
|
||||
true => write!(p, "{self:?}")?,
|
||||
false => write!(p, "{}", p.tcx().item_name(def_id))?,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
ty::ParamConst {
|
||||
write!(p, "{}", self.name)?;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,10 @@ impl<'tcx> Region<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion) -> Region<'tcx> {
|
||||
pub fn new_placeholder(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
placeholder: ty::PlaceholderRegion<'tcx>,
|
||||
) -> Region<'tcx> {
|
||||
tcx.intern_region(ty::RePlaceholder(placeholder))
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +173,7 @@ impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
|
|||
Region::new_canonical_bound(tcx, var)
|
||||
}
|
||||
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion) -> Self {
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion<'tcx>) -> Self {
|
||||
Region::new_placeholder(tcx, placeholder)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -184,16 +184,6 @@ impl fmt::Debug for ty::BoundTy {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: fmt::Debug> fmt::Debug for ty::Placeholder<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.universe == ty::UniverseIndex::ROOT {
|
||||
write!(f, "!{:?}", self.bound)
|
||||
} else {
|
||||
write!(f, "!{}_{:?}", self.universe.index(), self.bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for GenericArg<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.kind() {
|
||||
|
|
@ -294,8 +284,8 @@ TrivialTypeTraversalImpls! {
|
|||
// interners).
|
||||
TrivialTypeTraversalAndLiftImpls! {
|
||||
// tidy-alphabetical-start
|
||||
crate::ty::BoundTy,
|
||||
crate::ty::ParamTy,
|
||||
crate::ty::PlaceholderType,
|
||||
crate::ty::instance::ReifyReason,
|
||||
rustc_hir::def_id::DefId,
|
||||
// tidy-alphabetical-end
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>;
|
|||
pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>;
|
||||
pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>;
|
||||
pub type TypingMode<'tcx> = ir::TypingMode<TyCtxt<'tcx>>;
|
||||
pub type Placeholder<'tcx, T> = ir::Placeholder<TyCtxt<'tcx>, T>;
|
||||
|
||||
pub trait Article {
|
||||
fn article(&self) -> &'static str;
|
||||
|
|
@ -508,7 +509,7 @@ impl<'tcx> Ty<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType) -> Ty<'tcx> {
|
||||
pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> {
|
||||
Ty::new(tcx, Placeholder(placeholder))
|
||||
}
|
||||
|
||||
|
|
@ -957,7 +958,7 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
|
|||
Ty::new_param(tcx, param.index, param.name)
|
||||
}
|
||||
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType) -> Self {
|
||||
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Self {
|
||||
Ty::new_placeholder(tcx, placeholder)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -980,7 +980,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
fn report_sub_sup_conflict(
|
||||
&self,
|
||||
generic_param_scope: LocalDefId,
|
||||
var_origin: RegionVariableOrigin,
|
||||
var_origin: RegionVariableOrigin<'tcx>,
|
||||
sub_origin: SubregionOrigin<'tcx>,
|
||||
sub_region: Region<'tcx>,
|
||||
sup_origin: SubregionOrigin<'tcx>,
|
||||
|
|
@ -1051,7 +1051,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
if sub_region.is_error() | sup_region.is_error() { err.delay_as_bug() } else { err.emit() }
|
||||
}
|
||||
|
||||
fn report_inference_failure(&self, var_origin: RegionVariableOrigin) -> Diag<'_> {
|
||||
fn report_inference_failure(&self, var_origin: RegionVariableOrigin<'tcx>) -> Diag<'_> {
|
||||
let br_string = |br: ty::BoundRegionKind| {
|
||||
let mut s = match br {
|
||||
ty::BoundRegionKind::Named(def_id) => self.tcx.item_name(def_id).to_string(),
|
||||
|
|
|
|||
|
|
@ -566,13 +566,10 @@ fn plug_infer_with_placeholders<'tcx>(
|
|||
ty,
|
||||
Ty::new_placeholder(
|
||||
self.infcx.tcx,
|
||||
ty::Placeholder {
|
||||
universe: self.universe,
|
||||
bound: ty::BoundTy {
|
||||
var: self.next_var(),
|
||||
kind: ty::BoundTyKind::Anon,
|
||||
},
|
||||
},
|
||||
ty::Placeholder::new(
|
||||
self.universe,
|
||||
ty::BoundTy { var: self.next_var(), kind: ty::BoundTyKind::Anon },
|
||||
),
|
||||
),
|
||||
)
|
||||
else {
|
||||
|
|
@ -595,10 +592,10 @@ fn plug_infer_with_placeholders<'tcx>(
|
|||
ct,
|
||||
ty::Const::new_placeholder(
|
||||
self.infcx.tcx,
|
||||
ty::Placeholder {
|
||||
universe: self.universe,
|
||||
bound: ty::BoundConst { var: self.next_var() },
|
||||
},
|
||||
ty::Placeholder::new(
|
||||
self.universe,
|
||||
ty::BoundConst { var: self.next_var() },
|
||||
),
|
||||
),
|
||||
)
|
||||
else {
|
||||
|
|
@ -626,13 +623,13 @@ fn plug_infer_with_placeholders<'tcx>(
|
|||
r,
|
||||
ty::Region::new_placeholder(
|
||||
self.infcx.tcx,
|
||||
ty::Placeholder {
|
||||
universe: self.universe,
|
||||
bound: ty::BoundRegion {
|
||||
ty::Placeholder::new(
|
||||
self.universe,
|
||||
ty::BoundRegion {
|
||||
var: self.next_var(),
|
||||
kind: ty::BoundRegionKind::Anon,
|
||||
},
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -756,10 +756,10 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
|
|||
self.idx += 1;
|
||||
Ty::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderType {
|
||||
universe: ty::UniverseIndex::ROOT,
|
||||
bound: ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
|
||||
},
|
||||
ty::PlaceholderType::new(
|
||||
ty::UniverseIndex::ROOT,
|
||||
ty::BoundTy { var: idx, kind: ty::BoundTyKind::Anon },
|
||||
),
|
||||
)
|
||||
} else {
|
||||
t.super_fold_with(self)
|
||||
|
|
@ -772,10 +772,7 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
|
|||
self.idx += 1;
|
||||
ty::Const::new_placeholder(
|
||||
self.tcx,
|
||||
ty::PlaceholderConst {
|
||||
universe: ty::UniverseIndex::ROOT,
|
||||
bound: ty::BoundConst { var: idx },
|
||||
},
|
||||
ty::PlaceholderConst::new(ty::UniverseIndex::ROOT, ty::BoundConst { var: idx }),
|
||||
)
|
||||
} else {
|
||||
c.super_fold_with(self)
|
||||
|
|
|
|||
|
|
@ -220,9 +220,9 @@ pub fn with_replaced_escaping_bound_vars<
|
|||
/// The inverse of [`BoundVarReplacer`]: replaces placeholders with the bound vars from which they came.
|
||||
pub struct PlaceholderReplacer<'a, 'tcx> {
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
|
||||
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
|
||||
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundConst>,
|
||||
mapped_regions: FxIndexMap<ty::PlaceholderRegion<'tcx>, ty::BoundRegion>,
|
||||
mapped_types: FxIndexMap<ty::PlaceholderType<'tcx>, ty::BoundTy>,
|
||||
mapped_consts: FxIndexMap<ty::PlaceholderConst<'tcx>, ty::BoundConst>,
|
||||
universe_indices: &'a [Option<ty::UniverseIndex>],
|
||||
current_index: ty::DebruijnIndex,
|
||||
}
|
||||
|
|
@ -230,9 +230,9 @@ pub struct PlaceholderReplacer<'a, 'tcx> {
|
|||
impl<'a, 'tcx> PlaceholderReplacer<'a, 'tcx> {
|
||||
pub fn replace_placeholders<T: TypeFoldable<TyCtxt<'tcx>>>(
|
||||
infcx: &'a InferCtxt<'tcx>,
|
||||
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
|
||||
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
|
||||
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundConst>,
|
||||
mapped_regions: FxIndexMap<ty::PlaceholderRegion<'tcx>, ty::BoundRegion>,
|
||||
mapped_types: FxIndexMap<ty::PlaceholderType<'tcx>, ty::BoundTy>,
|
||||
mapped_consts: FxIndexMap<ty::PlaceholderConst<'tcx>, ty::BoundConst>,
|
||||
universe_indices: &'a [Option<ty::UniverseIndex>],
|
||||
value: T,
|
||||
) -> T {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::{ControlFlow, Deref};
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldabl
|
|||
use crate::inherent::*;
|
||||
use crate::lift::Lift;
|
||||
use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
||||
use crate::{self as ty, DebruijnIndex, Interner};
|
||||
use crate::{self as ty, DebruijnIndex, Interner, UniverseIndex};
|
||||
|
||||
/// `Binder` is a binder for higher-ranked lifetimes or types. It is part of the
|
||||
/// compiler's representation for things like `for<'a> Fn(&'a isize)`
|
||||
|
|
@ -948,3 +949,55 @@ pub enum BoundVarIndexKind {
|
|||
Bound(DebruijnIndex),
|
||||
Canonical,
|
||||
}
|
||||
|
||||
/// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are
|
||||
/// identified by both a universe, as well as a name residing within that universe. Distinct bound
|
||||
/// regions/types/consts within the same universe simply have an unknown relationship to one
|
||||
/// another.
|
||||
#[derive_where(Clone, PartialEq, Ord, Hash; I: Interner, T)]
|
||||
#[derive_where(PartialOrd; I: Interner, T: Ord)]
|
||||
#[derive_where(Copy; I: Interner, T: Copy, T)]
|
||||
#[derive_where(Eq; T)]
|
||||
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
|
||||
#[cfg_attr(
|
||||
feature = "nightly",
|
||||
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
|
||||
)]
|
||||
pub struct Placeholder<I: Interner, T> {
|
||||
pub universe: UniverseIndex,
|
||||
pub bound: T,
|
||||
#[type_foldable(identity)]
|
||||
#[type_visitable(ignore)]
|
||||
_tcx: PhantomData<fn() -> I>,
|
||||
}
|
||||
|
||||
impl<I: Interner, T> Placeholder<I, T> {
|
||||
pub fn new(universe: UniverseIndex, bound: T) -> Self {
|
||||
Placeholder { universe, bound, _tcx: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T: fmt::Debug> fmt::Debug for ty::Placeholder<I, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.universe == ty::UniverseIndex::ROOT {
|
||||
write!(f, "!{:?}", self.bound)
|
||||
} else {
|
||||
write!(f, "!{}_{:?}", self.universe.index(), self.bound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, U: Interner, T> Lift<U> for Placeholder<I, T>
|
||||
where
|
||||
T: Lift<U>,
|
||||
{
|
||||
type Lifted = Placeholder<U, T::Lifted>;
|
||||
|
||||
fn lift_to_interner(self, cx: U) -> Option<Self::Lifted> {
|
||||
Some(Placeholder {
|
||||
universe: self.universe,
|
||||
bound: self.bound.lift_to_interner(cx)?,
|
||||
_tcx: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ use std::fmt;
|
|||
use crate::{
|
||||
AliasTerm, AliasTy, Binder, ClosureKind, CoercePredicate, ExistentialProjection,
|
||||
ExistentialTraitRef, FnSig, HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate,
|
||||
PatternKind, ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef, UnevaluatedConst,
|
||||
PatternKind, Placeholder, ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef,
|
||||
UnevaluatedConst,
|
||||
};
|
||||
|
||||
pub trait IrPrint<T> {
|
||||
|
|
@ -23,15 +24,6 @@ macro_rules! define_display_via_print {
|
|||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T> fmt::Display for Binder<I, T>
|
||||
where
|
||||
I: IrPrint<Binder<I, T>>,
|
||||
{
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
<I as IrPrint<Binder<I, T>>>::print(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! define_debug_via_print {
|
||||
($($ty:ident),+ $(,)?) => {
|
||||
$(
|
||||
|
|
@ -71,6 +63,24 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T> fmt::Display for Binder<I, T>
|
||||
where
|
||||
I: IrPrint<Binder<I, T>>,
|
||||
{
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
<I as IrPrint<Binder<I, T>>>::print(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: Interner, T> fmt::Display for Placeholder<I, T>
|
||||
where
|
||||
I: IrPrint<Placeholder<I, T>>,
|
||||
{
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
<I as IrPrint<Placeholder<I, T>>>::print(self, fmt)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "nightly")]
|
||||
mod into_diag_arg_impls {
|
||||
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ pub use InferTy::*;
|
|||
pub use RegionKind::*;
|
||||
pub use TyKind::*;
|
||||
pub use Variance::*;
|
||||
pub use binder::*;
|
||||
pub use binder::{Placeholder, *};
|
||||
pub use canonical::*;
|
||||
pub use const_kind::*;
|
||||
pub use flags::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue