Skip to content
ZOLO / TE301 Type · error

generic type argument count mismatch

The number of type arguments supplied does not match the generic's declared parameter count.

Why this fires

A generic type was used with the wrong number of type arguments — either in a type annotation (Pair<int> when Pair takes two parameters) or in an impl header (impl Foo<T> on a target whose declared arity doesn't match, or on a non-generic target).

struct Pair<T, U> { first: T, second: U }

let p: Pair<int> = Pair { first: 1, second: "hello" }
//     ^^^^^^^^^ error[TE301]: type 'Pair' expects 2 type argument(s), found 1
enum Result<T, E> { Ok(T), Err(E) }

impl Result<T> {
//   ^^^^^^^^^ error[TE301]: impl on 'Result' declares 1 type parameter(s), but 'Result' has 2
    fn id(self) -> bool { return true }
}

Fix it

Match the type's declared arity:

let p: Pair<int, str> = Pair { first: 1, second: "hello" }   // ok
impl Result<T, E> {
    fn id(self) -> bool { return true }
}

See also

Fixed array and const generic arguments also use TE301 when a size is not a nonnegative static integer, an array literal has the wrong length, or a call cannot infer its const parameter. Use [T; N] in the formal type to preserve a fixed array proof. Dynamic array/Any erasure, length-changing methods, phantom const nominal parameters, and unsupported size ABI surfaces receive this diagnostic; see fixed arrays and const generics.

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br