我在玩弄一些代码时,做出了以下观察:
let x = 1;
let () = x;
error: mismatched types [E0308]
note: expected type `_`
note: found type `()`
这显然行不通,但我期望的错误类型应该是i32
而不是_
。我发现对于未指定类型的浮点文字面量(例如1.0
),情况也是如此。
为什么会这样呢?类型不应该已经作为默认值而知道吗?
更新:从Rust 1.12开始,错误信息更加详细:
expected integral variable, found ()
= note: expected type `{integer}`
= note: found type `()`