在文档中很难找到这一点.这甚至可能是一个由两部分组成的问题:
{integer}
和{float}
是某种特定基元类型的语言别名吗?将一个类型名用大括号括起来意味着什么
例子:
错误:在当前数据库中找不到类型
{integer}
的名为pow
的方法
在文档中很难找到这一点.这甚至可能是一个由两部分组成的问题:
{integer}
和{float}
是某种特定基元类型的语言别名吗?
将一个类型名用大括号括起来意味着什么
例子:
错误:在当前数据库中找不到类型
{integer}
的名为pow
的方法
{integer}
是一个整数值,其具体类型未指定,编译器尚未推断出;以下代码:
fn main() {
let x = 1;
let () = x;
}
将导致以下错误:
error[E0308]: mismatched types
--> <anon>:3:9
|
3 | let () = x;
| ^^ expected integral variable, found ()
|
= note: expected type `{integer}`
= note: found type `()`
浮点数也会发生同样的情况:
fn main() {
let x = 1.0;
let () = x;
}
error[E0308]: mismatched types
--> <anon>:3:9
|
3 | let () = x;
| ^^ expected floating-point variable, found ()
|
= note: expected type `{float}`
= note: found type `()`
因为无效赋值let () = x
导致的编译错误是在类型推断发生之前抛出的.
换句话说,直到编译达到类型推断阶段,在该阶段中,一个整数或一个没有指定具体类型的浮点将被识别(例如,基于函数应用)或分配默认类型,i32
代表整数,f64
代表浮点,编译错误将把它称为{integer}
或{float}
.