3
我玩弄一些代码,并提出以下意见:何时将数字文字分配给默认类型?
let x = 1;
let() = x;
error: mismatched types [E0308]
note: expected type `_`
note: found type `()`
这显然会失败,但我期待错误地指出,预期的类型是i32
,不_
。我发现同样的情况发生在未指定类型的浮动字面上,例如1.0
。
这是为什么?不应该将该类型称为默认类型?
更新:铁锈1.12,错误消息是更多的信息:
expected integral variable, found()
= note: expected type `{integer}`
= note: found type `()`
我觉得失败太明显了。 typechecker没有足够的实际插入默认值,因为这是行不通的。我只见过错误消息中的默认值,当时这是一系列关闭和泛型方法 –