Expand description
Each item can involve three kinds of predicates:
- input aka required predicates: the predicates required to mention the item. These are usually
where
clauses (or equivalent) on the item:
ⓘ
struct Foo<T: Clone> { ... }
trait Foo<T> where T: Clone { ... }
fn function<I>() where I: Iterator, I::Item: Clone { ... }
- output aka implied predicates: the predicates that are implied by the presence of this item in a signature. This is mostly trait parent predicates:
ⓘ
trait Foo: Clone { ... }
fn bar<T: Foo>() {
// from `T: Foo` we can deduce `T: Clone`
}
This could also include implied predicates such as &'a T
implying T: 'a
but we don’t
consider these.
- “self” predicate: that’s the special
Self: Trait
predicate in scope within a trait declaration or implementation for traitTrait
.
Note that within a given item the polarity is reversed: input predicates are the ones that can be assumed to hold and output predicates must be proven to hold. The “self” predicate is both assumed and proven within an impl block, and just assumed within a trait declaration block.
The current implementation considers all predicates on traits to be outputs, which has the benefit of reducing the size of signatures. Moreover, the rules on which bounds are required vs implied are subtle. We may change this if this proves to be a problem.
Traits§
Functions§
- erase_
and_ norm - erase_
free_ 🔒regions - Erase free regions from the given value. Largely copied from
tcx.erase_regions
, but also erases bound regions that are bound outsidevalue
, so we can call this function inside aBinder
. - implied_
predicates - The predicates that can be deduced from the presence of this item in a signature. We only
consider predicates implied by traits here, not implied bounds such as
&'a T
implyingT: 'a
. E.g. - is_
sized_ related_ trait - Returns true whenever
def_id
isMetaSized
,Sized
orPointeeSized
. - normalize_
bound_ val - Given our currently hacky handling of binders, in order for trait resolution to work we must empty out the binders of trait refs. Specifically it’s so that we can reconnect associated type constraints with the trait ref they come from, given that the projection in question doesn’t track the right binder currently.
- predicates_
defined_ on - Returns a list of type predicates for the definition with ID
def_id
, including inferred lifetime constraints. This is the basic list of predicates we use for essentially all items. - prune_
sized_ 🔒predicates - Given a
GenericPredicates
, prune every occurence of a sized-related clause. Prunes bounds of the shapeT: MetaSized
,T: Sized
orT: PointeeSized
. - required_
predicates - The predicates that must hold to mention this item. E.g.
- self_
predicate - The special “self” predicate on a trait.