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 1enum 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" } // okimpl Result<T, E> {
fn id(self) -> bool { return true }
}See also¶
- /docs/advanced-types — generic structs, enums, and
implblocks.