Function rustc_typeck::impl_wf_check::impl_wf_check[][src]

pub fn impl_wf_check<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
🔬 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?

Checks that all the type/lifetime parameters on an impl also appear in the trait ref or self-type (or are constrained by a where-clause). These rules are needed to ensure that, given a trait ref like <T as Trait<U>>, we can derive the values of all parameters on the impl (which is needed to make specialization possible).

However, in the case of lifetimes, we only enforce these rules if the lifetime parameter is used in an associated type. This is a concession to backwards compatibility; see comment at the end of the fn for details.

Example:

This example is not tested
impl<T> Trait<Foo> for Bar { ... }
//   ^ T does not appear in `Foo` or `Bar`, error!

impl<T> Trait<Foo<T>> for Bar { ... }
//   ^ T appears in `Foo<T>`, ok.

impl<T> Trait<Foo> for Bar where Bar: Iterator<Item=T> { ... }
//   ^ T is bound to `<Bar as Iterator>::Item`, ok.

impl<'a> Trait<Foo> for Bar { }
//   ^ 'a is unused, but for back-compat we allow it

impl<'a> Trait<Foo> for Bar { type X = &'a i32; }
//   ^ 'a is unused and appears in assoc type, error