Sisu
E0137

Type arguments that do not fit

Error

Built from the repository at commit a8614dc.

A generic class, enum or function takes one type argument for each of its type parameters, written in < and > after its name: Stack<i64> for class Stack<T>. A declaration without type parameters takes none, and a value takes none.

Why

The type arguments say what each type parameter stands for, so a generic name needs all of them, and a name that is not generic has nothing for them to stand for.

In an expression, a<b, c>(d) reads as a call of a with the type arguments b and c, since a ( follows the >. When a is a value, the < and > were meant as comparisons: put the first one in parentheses, (a < b), and the line reads as two comparisons. The same holds for a field, as in p.x<b, c>(d), for a variant without a payload of an enum that is not generic, and for an f64 constant. After a method of a built-in type, as in xs.len<b, c>(d), the comparison is of what the method returns, so call it: (xs.len() < b). When the method takes arguments, only you know which, so the help says nothing.

A variant takes its enum's type arguments, so they go on the enum: Tree<i64>.Node(...), not Tree.Node<i64>(...).

When a declaration that is not generic is given type arguments, as in Point<i64>(x: 1), the fix removes them. When a generic one is given too many or too few, write one type for each of its type parameters.

Broken

fn both(x: bool, y: bool) -> bool {
    x && y
}

fn main() {
    let a = 1
    let b = 2
    let c = 3
    let d = 4
    print(both(a < b, c > (d)))
}

What sisu says

error[E0137]: `a` is not generic
  --> E0137.sisu:10:16
   |
10 |     print(both(a < b, c > (d)))
   |                ^
   |
   = help: to compare, write `(a < b)`

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0137

Fixed

fn both(x: bool, y: bool) -> bool {
    x && y
}

fn main() {
    let a = 1
    let b = 2
    let c = 3
    let d = 4
    print(both((a < b), c > (d)))
}

Related

  • E0138: a type that cannot be a type argument.