rustc_hir_analysis::check::compare_impl_item

Function compare_number_of_generics

source
fn compare_number_of_generics<'tcx>(
    tcx: TyCtxt<'tcx>,
    impl_: AssocItem,
    trait_: AssocItem,
    delay: bool,
) -> Result<(), ErrorGuaranteed>
Expand description

Checks that the number of generics on a given assoc item in a trait impl is the same as the number of generics on the respective assoc item in the trait definition.

For example this code emits the errors in the following code:

trait Trait {
    fn foo();
    type Assoc<T>;
}

impl Trait for () {
    fn foo<T>() {}
    //~^ error
    type Assoc = u32;
    //~^ error
}

Notably this does not error on foo<T> implemented as foo<const N: u8> or foo<const N: u8> implemented as foo<const N: u32>. This is handled in compare_generic_param_kinds. This function also does not handle lifetime parameters