Operator on a value of a type parameter
ErrorA value whose type is a type parameter T, or names one, as [T] does, has no operators: no <, no ==, no + and no -. contains on a [T] compares elements with ==, so it is not there either.
Comparing an optional with None is allowed: on a T? or a [T]?, x == None and x != None test only whether a value is there, and need nothing from T. Comparing the values inside, as x == y on two T? does, is not allowed.
Why
T may stand for any type, and not every type has every operator: a class has no <, and an array has no +. Type parameters cannot yet say what their types must have, so a generic function may only move such values around: pass them, return them, and put them into fields, arrays and optionals. To compare or compute, write the function for the type it needs.
Broken
fn smaller<T>(a: T, b: T) -> bool {
a < b
}
fn main() {}
What sisu says
error[E0139]: `T` has no `<` --> E0139.sisu:2:5 | 2 | a < b | ^ this is a `T` sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0139
Fixed
fn smaller(a: i64, b: i64) -> bool {
a < b
}
fn main() {
print(smaller(1, 2))
}
Sisu