rustc_trait_selection::infer::region_constraints

Struct RegionConstraintCollector

Source
pub struct RegionConstraintCollector<'a, 'tcx> {
    storage: &'a mut RegionConstraintStorage<'tcx>,
    undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
}

Fields§

§storage: &'a mut RegionConstraintStorage<'tcx>§undo_log: &'a mut InferCtxtUndoLogs<'tcx>

Implementations§

Source§

impl<'tcx> RegionConstraintCollector<'_, 'tcx>

Source

pub fn leak_check( self, tcx: TyCtxt<'tcx>, outer_universe: UniverseIndex, max_universe: UniverseIndex, only_consider_snapshot: Option<&CombinedSnapshot<'tcx>>, ) -> Result<(), TypeError<TyCtxt<'tcx>>>

Searches new universes created during snapshot, looking for placeholders that may “leak” out from the universes they are contained in. If any leaking placeholders are found, then an Err is returned (typically leading to the snapshot being reversed). This algorithm only looks at placeholders which cannot be named by outer_universe, as this is the universe we’re currently checking for a leak.

The leak check used to be the only way we had to handle higher-ranked obligations. Now that we have integrated universes into the region solvers, this is no longer the case, but we retain the leak check for backwards compatibility purposes. In particular, it lets us make “early” decisions about whether a region error will be reported that are used in coherence and elsewhere – see #56105 and #59490 for more details. The eventual fate of the leak checker is not yet settled.

The leak checker works by searching for the following error patterns:

  • P1: P2, where P1 != P2
  • P1: R, where R is in some universe that cannot name P1

The idea here is that each of these patterns represents something that the region solver would eventually report as an error, so we can detect the error early. There is a fly in the ointment, though, in that this is not entirely true. In particular, in the future, we may extend the environment with implied bounds or other info about how placeholders relate to regions in outer universes. In that case, P1: R for example might become solvable.

§Summary of the implementation

The leak checks as follows. First, we construct a graph where R2: R1 implies R2 -> R1, and we compute the SCCs.

For each SCC S, we compute:

  • what placeholder P it must be equal to, if any
    • if there are multiple placeholders that must be equal, report an error because P1: P2
  • the minimum universe of its constituents

Then we walk the SCCs in dependency order and compute

  • what placeholder they must outlive transitively
    • if they must also be equal to a placeholder, report an error because P1: P2
  • minimum universe U of all SCCs they must outlive
    • if they must also be equal to a placeholder P, and U cannot name P, report an error, as that indicates P: R and R is in an incompatible universe

To improve performance and for the old trait solver caching to be sound, this takes an optional snapshot in which case we only look at region constraints added in that snapshot. If we were to not do that the leak_check during evaluation can rely on region constraints added outside of that evaluation. As that is not reflected in the cache key this would be unsound.

§Historical note

Older variants of the leak check used to report errors for these patterns, but we no longer do:

  • R: P1, even if R cannot name P1, because R = ’static is a valid sol’n
  • R: P1, R: P2, as above
Source§

impl<'tcx> RegionConstraintCollector<'_, 'tcx>

Source

pub fn num_region_vars(&self) -> usize

Source

pub fn region_constraint_data(&self) -> &RegionConstraintData<'tcx>

Source

pub fn take_and_reset_data(&mut self) -> RegionConstraintData<'tcx>

Takes (and clears) the current set of constraints. Note that the set of variables remains intact, but all relationships between them are reset. This is used during NLL checking to grab the set of constraints that arose from a particular operation.

We don’t want to leak relationships between variables between points because just because (say) r1 == r2 was true at some point P in the graph doesn’t imply that it will be true at some other point Q, in NLL.

Not legal during a snapshot.

Source

pub fn data(&self) -> &RegionConstraintData<'tcx>

Source

pub fn opportunistic_resolve_var( &mut self, tcx: TyCtxt<'tcx>, vid: RegionVid, ) -> Region<'tcx>

Resolves a region var to its value in the unification table, if it exists. Otherwise, it is resolved to the root ReVar in the table.

Source

pub fn probe_value( &mut self, vid: RegionVid, ) -> Result<Region<'tcx>, UniverseIndex>

Source

pub fn universe(&mut self, region: Region<'tcx>) -> UniverseIndex

Source

pub fn vars_since_snapshot( &self, value_count: usize, ) -> (Range<RegionVid>, Vec<RegionVariableOrigin>)

Source

pub fn region_constraints_added_in_snapshot( &self, mark: &Snapshot<'tcx>, ) -> bool

See InferCtxt::region_constraints_added_in_snapshot.

Auto Trait Implementations§

§

impl<'a, 'tcx> DynSend for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> DynSync for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> Freeze for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> !RefUnwindSafe for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> Send for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> Sync for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> Unpin for RegionConstraintCollector<'a, 'tcx>

§

impl<'a, 'tcx> !UnwindSafe for RegionConstraintCollector<'a, 'tcx>

Blanket Implementations§

Source§

impl<T> Aligned for T

Source§

const ALIGN: Alignment = _

Alignment of Self.
Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T, R> CollectAndApply<T, R> for T

§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

Source§

impl<T> Filterable for T

Source§

fn filterable( self, filter_name: &'static str, ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<P> IntoQueryParam<P> for P

Source§

impl<T> MaybeResult<T> for T

Source§

type Error = !

Source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

Source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<I, T, U> Upcast<I, U> for T
where U: UpcastFrom<I, T>,

§

fn upcast(self, interner: I) -> U

§

impl<I, T> UpcastFrom<I, T> for T

§

fn upcast_from(from: T, _tcx: I) -> T

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync,

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: 16 bytes