< 返回版块

WingDust 发表于 2022-01-09 12:17


static mut E: Option<i32> = None;

fn main (){

let mut a =2;

// 变量 a 与 变量 E 的生命周期有区别吗?
loop{true;}
}

评论区

写评论
Neutron3529 2022-01-09 15:40

有区别 你可以随时把adrop掉,但E是drop不掉的。

error[E0507]: cannot move out of static item `E`
 --> test.rs:6:18
  |
6 |     unsafe {drop(E);}
  |                  ^ move occurs because `E` has type `X`, which does not implement the `Copy` trait

error: aborting due to previous error
1 共 1 条评论, 1 页