【发布时间】:2014-11-01 08:56:26
【问题描述】:
这个(很傻的)函数编译失败:
fn silliness(mut z: &mut int) {
z = &mut *z;
}
编译器输出:
$ rustc blah.rs
blah.rs:2:5: 2:16 error: cannot assign to `z` because it is borrowed
blah.rs:2 z = &mut *z;
^~~~~~~~~~~
blah.rs:2:14: 2:16 note: borrow of `z` occurs here
blah.rs:2 z = &mut *z;
^~
error: aborting due to previous error
在我看来,由于在任何时候都只有一个引用 z 指向的内容,所以应该没问题。什么不明白?
【问题讨论】:
标签: rust