error cannot-infer
Тип не удаётся вывести.
What it means#
Type inference is local (§3). When nothing in the context fixes a type, for example an empty list that is never used with elements, a generic argument not present in any parameter, or an ambiguous call (§4.8), the compiler asks for an annotation.
Example#
fn make<T>() -> T where T: Default => T.default()
fn main() io {
let x = make() // <- cannot-infer
print("{x}")
}error
cannot-infer
How to fix#
fn make<T>() -> T where T: Default => T.default()
fn main() io {
let x: i32 = make()
print("{x}")
}Add a type annotation to the binding, or pass explicit generic arguments (f<i32>()).