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


§storage: &'a mut RegionConstraintStorage<'tcx>§undo_log: &'a mut InferCtxtUndoLogs<'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).

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
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

Once all the constraints have been gathered, extract out the final data.

Not legal during a snapshot.

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.

Returns the universe for the given variable.

Returns the origin for the given variable.

Resolves the passed RegionVid to the root RegionVid in the unification table

If the Region is a ReVar, then resolves it either to the root value in the unification table, if it exists, or to the root ReVar in the table. If the Region is not a ReVar, just returns the Region itself.

See InferCtxt::region_constraints_added_in_snapshot.

Methods from Deref<Target = RegionConstraintStorage<'tcx>>§


fn rollback_undo_entry(&mut self, undo_entry: UndoLog<'tcx>)

Trait Implementations§

The resulting type after dereferencing.
Dereferences the value.
Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.


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