Skip to main content

E0042: Wrong Generic Arity

You used a generic type with the wrong number of type arguments.

Example

fn test() {
let x: Option = Option::Some(42); // Error: expects 1 generic argument, found 0
let y: Option<i64, bool> = Option::Some(42); // Error: expects 1 generic argument, found 2
let z: Result<i64> = Result::Ok(42); // Error: expects 2 generic arguments, found 1
}

How to fix

Provide the correct number of type arguments:

fn test() {
let x: Option<i64> = Option::Some(42); // OK
let y: Result<i64, bool> = Result::Ok(42); // OK
}

Option<T> takes exactly 1 type argument. Result<T, E> takes exactly 2.