【发布时间】:2015-02-15 19:45:00
【问题描述】:
我将问题简化为以下代码:
enum E {
E1,
}
fn f(e1: &E, e2: &E) {
match *e1 {
E::E1 => (),
}
match (*e1, *e2) {
(E::E1, E::E1) => (),
}
}
fn main() {}
第一个匹配没问题,第二个编译失败:
error[E0507]: cannot move out of borrowed content
--> src/main.rs:9:12
|
9 | match (*e1, *e2) {
| ^^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> src/main.rs:9:17
|
9 | match (*e1, *e2) {
| ^^^ cannot move out of borrowed content
这似乎是因为我正在构建一对借来的东西,Rust 试图将 e1 和 e2 移入其中。我发现如果我在枚举之前加上“#[derive(Copy, Clone)]”,我的代码就会编译。
【问题讨论】:
标签: rust