我正在玩一些代码,并做了以下观察:
let x = 1;
let () = x;
error: mismatched types [E0308]
note: expected type `_`
note: found type `()`
Run Code Online (Sandbox Code Playgroud)
这显然失败了,但我期待错误说明预期的类型i32不是_.我发现同样的情况发生在一个未指定类型的浮动文字中,例如1.0.
为什么会这样?这种类型不应该被称为默认类型吗?
更新:从Rust 1.12开始,错误消息提供更多信息:
expected integral variable, found ()
= note: expected type `{integer}`
= note: found type `()`
Run Code Online (Sandbox Code Playgroud)