该代码适用于:
fn main() {
let a: i32 = (1i32..10).sum();
let b = a.pow(2);
}
如果从a
中删除i32
类型,则会出现以下错误:
rustc 1.13.0 (2c6933acc 2016-11-07)
error: the type of this value must be known in this context
--> <anon>:3:13
|
5 | let b = a.pow(2);
| ^^^^^^^^
我本以为Rust会把(1i32..10)
变成i32
迭代器,然后sum()
知道返回i32
.我错过了什么?