3 ms·
I think you solve this by just giving an error In [0] fn bar(i: &u16) { i + 1 } In [1] let a = 8; // a is a i32. In [2] bar(&a) Out[2] Type error: a is
by gpm 8y ago
I think you solve this by just giving an error
In [0] fn bar(i: &u16) {
i + 1
}
In [1] let a = 8; // a is a i32.
In [2] bar(&a)
Out[2] Type error: a is a i32 and it needs to be a u16
In [3] let a: u16 = 8; // The original a is shadowed by the new a, the new a is a u16
In [4] bar(&a)
Out[4] 9
Or a similar situation where there isn't enough information to infer a type
In [0] let x = Vec::new();
Out[0] Type error: Need to know the type of x
In [1] let x: Vec<bool> = Vec::new();
In [2] x.push(true); // Note that if we had entered this at the same tiem as Vec::new() the type could have been inferred.
- richardwhiuk 8y agoThat forces you to write very unnatural Rust - it makes it a much clunkier language.