pub struct RegionInferenceContext<'tcx> {
data: Frozen<RegionInferenceContextInner<'tcx>>,
}Expand description
This contains data around region constraints and liveness, up to and after solving. All data is immutable.
Fields§
§data: Frozen<RegionInferenceContextInner<'tcx>>Implementations§
Source§impl<'tcx> RegionInferenceContext<'tcx>
impl<'tcx> RegionInferenceContext<'tcx>
Sourcepub(crate) fn get_var_name_and_span_for_region(
&self,
tcx: TyCtxt<'tcx>,
body: &Body<'tcx>,
local_names: &IndexSlice<Local, Option<Symbol>>,
upvars: &[&CapturedPlace<'tcx>],
fr: RegionVid,
) -> Option<(Option<Symbol>, Span)>
pub(crate) fn get_var_name_and_span_for_region( &self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, local_names: &IndexSlice<Local, Option<Symbol>>, upvars: &[&CapturedPlace<'tcx>], fr: RegionVid, ) -> Option<(Option<Symbol>, Span)>
Find the name and span of the variable corresponding to the given region.
The returned var will also be ensured to actually be used in body.
Sourcepub(crate) fn get_upvar_index_for_region(
&self,
tcx: TyCtxt<'tcx>,
fr: RegionVid,
) -> Option<usize>
pub(crate) fn get_upvar_index_for_region( &self, tcx: TyCtxt<'tcx>, fr: RegionVid, ) -> Option<usize>
Search the upvars (if any) to find one that references fr. Return its index.
Sourcepub(crate) fn get_upvar_name_and_span_for_region(
&self,
tcx: TyCtxt<'tcx>,
upvars: &[&CapturedPlace<'tcx>],
upvar_index: usize,
) -> (Symbol, Span)
pub(crate) fn get_upvar_name_and_span_for_region( &self, tcx: TyCtxt<'tcx>, upvars: &[&CapturedPlace<'tcx>], upvar_index: usize, ) -> (Symbol, Span)
Given the index of an upvar, finds its name and the span from where it was declared.
Sourcepub(crate) fn get_user_arg_index_for_region(
&self,
tcx: TyCtxt<'tcx>,
fr: RegionVid,
) -> Option<usize>
pub(crate) fn get_user_arg_index_for_region( &self, tcx: TyCtxt<'tcx>, fr: RegionVid, ) -> Option<usize>
Search the argument types for one that references fr (which should be a free region). Returns Some(_) with the index of the input if one is found.
N.B., in the case of a closure, the index is indexing into the signature as seen by the user - in particular, index 0 is not the implicit self parameter.
Sourcefn user_arg_index_to_local(
&self,
body: &Body<'tcx>,
user_arg_index: usize,
) -> Local
fn user_arg_index_to_local( &self, body: &Body<'tcx>, user_arg_index: usize, ) -> Local
Given the index of an argument as seen from the user (i.e. excluding implicit inputs), returns the corresponding MIR local.
Source§impl<'tcx> RegionInferenceContext<'tcx>
impl<'tcx> RegionInferenceContext<'tcx>
Sourcepub(super) fn to_error_region(&self, r: RegionVid) -> Option<Region<'tcx>>
pub(super) fn to_error_region(&self, r: RegionVid) -> Option<Region<'tcx>>
Converts a region inference variable into a ty::Region that
we can use for error reporting. If r is universally bound,
then we use the name that we have on record for it. If r is
existentially bound, then we check its inferred value and try
to find a good name from that. Returns None if we can’t find
one (e.g., this is just some random part of the CFG).
Sourcepub(super) fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid>
pub(super) fn to_error_region_vid(&self, r: RegionVid) -> Option<RegionVid>
Returns the RegionVid corresponding to the region returned by
to_error_region.
Sourcefn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
fn name_regions<T>(&self, tcx: TyCtxt<'tcx>, ty: T) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
Map the regions in the type to named regions, where possible.
Sourcefn is_closure_fn_mut(&self, fr: RegionVid) -> bool
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool
Returns true if a closure is inferred to be an FnMut closure.
Source§impl<'tcx> RegionInferenceContext<'tcx>
impl<'tcx> RegionInferenceContext<'tcx>
Sourcepub(crate) fn dump_mir(
&self,
tcx: TyCtxt<'tcx>,
out: &mut dyn Write,
) -> Result<()>
pub(crate) fn dump_mir( &self, tcx: TyCtxt<'tcx>, out: &mut dyn Write, ) -> Result<()>
Write out our state into the .mir files.
Sourcefn for_each_constraint(
&self,
tcx: TyCtxt<'tcx>,
with_msg: &mut dyn FnMut(&str) -> Result<()>,
) -> Result<()>
fn for_each_constraint( &self, tcx: TyCtxt<'tcx>, with_msg: &mut dyn FnMut(&str) -> Result<()>, ) -> Result<()>
Debugging aid: Invokes the with_msg callback repeatedly with
our internal region constraints. These are dumped into the
-Zdump-mir file so that we can figure out why the region
inference resulted in the values that it did when debugging.
Source§impl<'tcx> RegionInferenceContext<'tcx>
impl<'tcx> RegionInferenceContext<'tcx>
Source§impl<'tcx> RegionInferenceContext<'tcx>
impl<'tcx> RegionInferenceContext<'tcx>
Sourcepub(crate) fn name_regions_for_member_constraint<T>(
&self,
tcx: TyCtxt<'tcx>,
ty: T,
) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
pub(crate) fn name_regions_for_member_constraint<T>(
&self,
tcx: TyCtxt<'tcx>,
ty: T,
) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
Map the regions in the type to named regions. This is similar to what
infer_opaque_types does, but can infer any universal region, not only
ones from the args for the opaque type. It also doesn’t double check
that the regions produced are in fact equal to the named region they are
replaced with. This is fine because this function is only to improve the
region names in error messages.
This differs from MirBorrowckCtxt::name_regions since it is particularly
lax with mapping region vids that are shorter than a universal region to
that universal region. This is useful for member region constraints since
we want to suggest a universal region name to capture even if it’s technically
not equal to the error region.
Methods from Deref<Target = RegionInferenceContextInner<'tcx>>§
Sourcepub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx
pub(crate) fn regions(&self) -> impl Iterator<Item = RegionVid> + 'tcx
Returns an iterator over all the region indices.
Sourcepub(crate) fn to_region_vid(&self, r: Region<'tcx>) -> RegionVid
pub(crate) fn to_region_vid(&self, r: Region<'tcx>) -> RegionVid
Given a universal region in scope on the MIR, returns the corresponding index.
Panics if r is not a registered universal region, most notably
if it is a placeholder. Handling placeholders requires access to the
MirTypeckRegionConstraints.
Sourcepub(crate) fn outlives_constraints(
&self,
) -> impl Iterator<Item = OutlivesConstraint<'tcx>>
pub(crate) fn outlives_constraints( &self, ) -> impl Iterator<Item = OutlivesConstraint<'tcx>>
Returns an iterator over all the outlives constraints.
Sourcepub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_>)
pub(crate) fn annotate(&self, tcx: TyCtxt<'tcx>, err: &mut Diag<'_>)
Adds annotations for #[rustc_regions]; see UniversalRegions::annotate.
Sourcepub(crate) fn region_contains_point(&self, r: RegionVid, p: Location) -> bool
pub(crate) fn region_contains_point(&self, r: RegionVid, p: Location) -> bool
Returns true if the region r contains the point p.
Panics if called before solve() executes,
Sourcepub(crate) fn first_non_contained_inclusive(
&self,
r: RegionVid,
block: BasicBlock,
start: usize,
end: usize,
) -> Option<usize>
pub(crate) fn first_non_contained_inclusive( &self, r: RegionVid, block: BasicBlock, start: usize, end: usize, ) -> Option<usize>
Returns the lowest statement index in start..=end which is not contained by r.
Panics if called before solve() executes.
Sourcepub(crate) fn region_value_str(&self, r: RegionVid) -> String
pub(crate) fn region_value_str(&self, r: RegionVid) -> String
Returns access to the value of r for debugging purposes.
pub(crate) fn placeholders_contained_in( &self, r: RegionVid, ) -> impl Iterator<Item = PlaceholderRegion<'tcx>>
Sourcepub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid
pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid
Like universal_upper_bound, but returns an approximation more suitable
for diagnostics. If r contains multiple disjoint universal regions
(e.g. ’a and ’b in fn foo<'a, 'b> { ... }, we pick the lower-numbered region.
This corresponds to picking named regions over unnamed regions
(e.g. picking early-bound regions over a closure late-bound region).
This means that the returned value may not be a true upper bound, since only ’static is known to outlive disjoint universal regions. Therefore, this method should only be used in diagnostic code, where displaying some named universal region is better than falling back to ’static.
Sourcepub(super) fn max_nameable_universe(
&self,
scc: ConstraintSccIndex,
) -> UniverseIndex
pub(super) fn max_nameable_universe( &self, scc: ConstraintSccIndex, ) -> UniverseIndex
The largest universe of any region nameable from this SCC.
pub(crate) fn constraint_path_between_regions( &self, from_region: RegionVid, to_region: RegionVid, ) -> Option<Vec<OutlivesConstraint<'tcx>>>
Sourcepub(crate) fn constraint_path_to(
&self,
from_region: RegionVid,
target_test: impl Fn(RegionVid) -> bool,
include_placeholder_static: bool,
) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)>
pub(crate) fn constraint_path_to( &self, from_region: RegionVid, target_test: impl Fn(RegionVid) -> bool, include_placeholder_static: bool, ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)>
Walks the graph of constraints (where 'a: 'b is considered
an edge 'a -> 'b) to find a path from from_region to
to_region.
Returns: a series of constraints as well as the region R
that passed the target test.
If include_static_outlives_all is true, then the synthetic
outlives constraints 'static -> a for every region a are
considered in the search, otherwise they are ignored.
Sourcefn find_constraint_path_between_regions_inner(
&self,
ignore_opaque_type_constraints: bool,
from_region: RegionVid,
target_test: impl Fn(RegionVid) -> bool,
include_placeholder_static: bool,
) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)>
fn find_constraint_path_between_regions_inner( &self, ignore_opaque_type_constraints: bool, from_region: RegionVid, target_test: impl Fn(RegionVid) -> bool, include_placeholder_static: bool, ) -> Option<(Vec<OutlivesConstraint<'tcx>>, RegionVid)>
The constraints we get from equating the hidden type of each use of an opaque with its final hidden type may end up getting preferred over other, potentially longer constraint paths.
Given that we compute the final hidden type by relying on this existing constraint path, this can easily end up hiding the actual reason for why we require these regions to be equal.
To handle this, we first look at the path while ignoring these constraints and then
retry while considering them. This is not perfect, as the from_region may have already
been partially related to its argument region, so while we rely on a member constraint
to get a complete path, the most relevant step of that path already existed before then.
Sourcepub(crate) fn find_sub_region_live_at(
&self,
fr1: RegionVid,
location: Location,
) -> RegionVid
pub(crate) fn find_sub_region_live_at( &self, fr1: RegionVid, location: Location, ) -> RegionVid
Finds some region R such that fr1: R and R is live at location.
Sourcepub(crate) fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx>
pub(crate) fn region_definition(&self, r: RegionVid) -> &RegionDefinition<'tcx>
Get the region definition of r.
Sourcepub(crate) fn upper_bound_in_region_scc(
&self,
r: RegionVid,
upper: RegionVid,
) -> bool
pub(crate) fn upper_bound_in_region_scc( &self, r: RegionVid, upper: RegionVid, ) -> bool
Check if the SCC of r contains upper, a free region.
pub(crate) fn universal_regions(&self) -> &UniversalRegions<'tcx>
Sourcepub(crate) fn best_blame_constraint(
&self,
from_region: RegionVid,
from_region_origin: NllRegionVariableOrigin<'tcx>,
to_region: RegionVid,
) -> BestBlame<'tcx>
pub(crate) fn best_blame_constraint( &self, from_region: RegionVid, from_region_origin: NllRegionVariableOrigin<'tcx>, to_region: RegionVid, ) -> BestBlame<'tcx>
Tries to find the best constraint to blame for the fact that
R: from_region, where R is some region that meets
target_test. This works by following the constraint graph,
creating a constraint path that forces R to outlive
from_region, and then finding the best choices within that
path to blame.
pub(crate) fn universe_info( &self, universe: UniverseIndex, ) -> UniverseInfo<'tcx>
Sourcepub(crate) fn find_loop_terminator_location(
&self,
r: RegionVid,
body: &Body<'_>,
) -> Option<Location>
pub(crate) fn find_loop_terminator_location( &self, r: RegionVid, body: &Body<'_>, ) -> Option<Location>
Tries to find the terminator of the loop in which the region ‘r’ resides. Returns the location of the terminator if found.
Sourcepub(crate) fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex>
pub(crate) fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex>
Access to the SCC constraint graph. This can be used to quickly under-approximate the regions which are equal to each other and their relative orderings.
pub(crate) fn liveness_constraints(&self) -> &LivenessValues
Sourcepub(crate) fn is_loan_live_at(
&self,
loan_idx: BorrowIndex,
location: Location,
) -> bool
pub(crate) fn is_loan_live_at( &self, loan_idx: BorrowIndex, location: Location, ) -> bool
Returns whether the loan_idx is live at the given location: whether its issuing
region is contained within the type of a variable that is live at this point.
Note: for now, the sets of live loans is only available when using -Zpolonius=next.
Trait Implementations§
Auto Trait Implementations§
impl<'tcx> !DynSend for RegionInferenceContext<'tcx>
impl<'tcx> !DynSync for RegionInferenceContext<'tcx>
impl<'tcx> !Freeze for RegionInferenceContext<'tcx>
impl<'tcx> !RefUnwindSafe for RegionInferenceContext<'tcx>
impl<'tcx> !Send for RegionInferenceContext<'tcx>
impl<'tcx> !Sync for RegionInferenceContext<'tcx>
impl<'tcx> !UnwindSafe for RegionInferenceContext<'tcx>
impl<'tcx> Unpin for RegionInferenceContext<'tcx>
impl<'tcx> UnsafeUnpin for RegionInferenceContext<'tcx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<K> IntoQueryKey<K> for K
impl<K> IntoQueryKey<K> for K
Source§fn into_query_key(self) -> K
fn into_query_key(self) -> K
Self to K.
This should always be a very cheap conversion, e.g. LocalDefId::to_def_id.Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
Source§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 904 bytes