Module utils

Source
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 trait Trait.

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§

ToPolyTraitRef

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 outside value, so we can call this function inside a Binder.
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 implying T: 'a. E.g.
is_sized_related_trait
Returns true whenever def_id is MetaSized, Sized or PointeeSized.
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 shape T: MetaSized, T: Sized or T: PointeeSized.
required_predicates
The predicates that must hold to mention this item. E.g.
self_predicate
The special “self” predicate on a trait.