我写了这个简单的程序:
trait Command<T> {
fn execute(&self, &mut T);
}
fn main() {
let x = 0;
}
我rustc --edition=2018 main.rs
编译这一点,得到的错误信息:
error: expected one of `:` or `@`, found `)`
--> main.rs:2:29
|
2 | fn execute(&self, &mut T);
| ^ expected one of `:` or `@` here
通过rustc --edition=2015 main.rs
或rustc main.rs
编译不会导致这个错误,虽然也有一些警告。
什么是与此代码的问题?
匿名特性参数已经在2018版被删除:No more anonymous trait parameters。
_:
前加&mut T
如果你想忽略的参数:
trait Command<T> {
fn execute(&self, _: &mut T);
}
与rustc main.rs
作品编译,因为它默认为--edition=2015
。
事实上,如果你把你的main.rs
在新货的项目,然后从edition = "2018"
删除Cargo.toml
,并运行
cargo fix --edition
该货物将自动添加缺少的qazxsw POI。见qazxsw POI。