Module rustc::infer::outlives::obligations[][src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Code that handles "type-outlives" constraints like T: 'a. This is based on the outlives_components function defined on the tcx, but it adds a bit of heuristics on top, in particular to deal with associated types and projections.

When we process a given T: 'a obligation, we may produce two kinds of constraints for the region inferencer:

The key point is that once this function is done, we have reduced all of our "type-region outlives" obligations into relationships between individual regions.

One key input to this function is the set of "region-bound pairs". These are basically the relationships between type parameters and regions that are in scope at the point where the outlives obligation was incurred. When type-checking a function, particularly in the face of closures, this is not known until regionck runs! This is because some of those bounds come from things we have yet to infer.

Consider:

fn bar<T>(a: T, b: impl for<'a> Fn(&'a T));
fn foo<T>(x: T) {
    bar(x, |y| { ... })
         // ^ closure arg
}

Here, the type of y may involve inference variables and the like, and it may also contain implied bounds that are needed to type-check the closure body (e.g., here it informs us that T outlives the late-bound region 'a).

Note that by delaying the gathering of implied bounds until all inference information is known, we may find relationships between bound regions and other regions in the environment. For example, when we first check a closure like the one expected as argument to foo:

fn foo<U, F: for<'a> FnMut(&'a U)>(_f: F) {}

the type of the closure's first argument would be &'a ?U. We might later infer ?U to something like &'b u32, which would imply that 'b: 'a.

Re-exports

use hir::def_id::DefId;
use infer;
use infer::GenericKind;
use infer::InferCtxt;
use infer::RegionObligation;
use infer::SubregionOrigin;
use infer::VerifyBound;
use traits;
use ty;
use ty::Ty;
use ty::TyCtxt;
use ty::TypeFoldable;
use ty::subst::Subst;
use ty::subst::Substs;
use ty::outlives::Component;
use syntax::ast;

Structs

TypeOutlives [
Experimental
]