【发布时间】:2019-02-28 20:15:04
【问题描述】:
struct Abc {
a: i32,
}
fn main() {
let mut abc = Abc { a: 30 };
let xyz = &abc;
let q = *xyz;
}
编译代码出现以下错误:
error[E0507]: cannot move out of borrowed content
--> src/main.rs:11:13
|
11 | let q = *xyz;
| ^^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*xyz`
请帮助我了解这里出了什么问题。
【问题讨论】:
-
您能否进一步描述在这个特定示例中让您感到困惑的地方? This section 关于所有权的书可能会帮助您了解正在发生的事情。而且,还有dozens of other questions with that exact same error message。
-
下面的代码可以编译,但是有问题的代码有问题 "fn main() { let mut abc = 10; let xyz = &abc; let q = *xyz; }"
-
@user8070445 数字是
Copy类型,所以它们不会被移动。您的结构在分配给变量时将被移动,因为它不是Copy。
标签: syntax reference rust move-semantics borrowing