I was playing around with some code and made the following observation:
let x = 1;
let () = x;
error: mismatched types [E0308]
note: expected type `_`
note: found type `()`
This obviously fails, but I was expecting the error to state that the expected type was i32
, not _
. I found out that the same happens with a floating literal of an unspecified type, e.g. 1.0
.
Why is it so? Shouldn't the type already be known as the default?
Update: as of Rust 1.12, the error message is more informative:
expected integral variable, found ()
= note: expected type `{integer}`
= note: found type `()`
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…