Consider the following code:
fn main() {
let foo = 1;
let bar: i32 = -&foo; //ok, -1
let baz: i32 = &foo; //error, expected `i32`, found `&{integer}`
let bad: i32 = !&foo; //ok, -2
}
Playground
Reading through the Rust Reference I found that
Possible coercion sites are:
- let statements where an explicit type is given.
[…]
- Arguments for function calls
So let baz: i32 = &foo;
should also work since it’s a let statement with an explicit type given.
Why does it refuse to be compiled?