Closed
Description
#![feature(thread_local)]
#[thread_local]
static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
fn main() {
unsafe {
let mut x = X;
let _y = x.get_mut();
}
}
produces the following error:
thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: (MoveData { move_paths: [MovePath { place: _0 }, MovePath { place: _1 }, MovePath { place: _2 }, MovePath { place: _3 }, MovePath { place: _4 }], moves: [mp2@bb0[3], mp2@bb0[4], mp4@bb0[8], mp4@bb1[0], mp3@bb1[2], mp1@bb1[3], mp0@bb1[4]], loc_map: LocationMap { map: [[[], [], [], [mo0], [mo1], [], [], [], [mo2]], [[mo3], [], [mo4], [mo5], [mo6]]] }, path_map: [[mo6], [mo5], [mo0, mo1], [mo4], [mo2, mo3]], rev_lookup: MovePathLookup { locals: [mp0, mp1, mp2, mp3, mp4], projections: {} }, inits: [mp2@src/main.rs:8:21: 8:22 (Deep), mp1@src/main.rs:8:21: 8:22 (Deep), mp4@src/main.rs:9:18: 9:19 (Deep), mp3@src/main.rs:9:18: 9:29 (NonPanicPathOnly), mp0@src/main.rs:7:5: 10:6 (Deep)], init_loc_map: LocationMap { map: [[[], [], [in0], [in1], [], [], [], [in2], [in3]], [[], [in4], [], [], []]] }, init_path_map: [[in4], [in1], [in0], [in3], [in2]] }, [IllegalMove { cannot_move_out_of: IllegalMoveOrigin { span: src/main.rs:8:21: 8:22, kind: Static } }])', /checkout/src/libcore/result.rs:916:5
Also, the following code fails to compile due to a lifetime error, but doesn't crash the compiler:
#![feature(thread_local)]
#[thread_local]
static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
fn main() {
unsafe {
let mut _x = X.get_mut();
}
}
Output:
error[E0597]: borrowed value does not live long enough
--> src/main.rs:8:22
|
8 | let mut _x = X.get_mut();
| ^ - temporary value dropped here while still borrowed
| |
| temporary value does not live long enough
9 | }
| - temporary value needs to live until here
|
= note: consider using a `let` binding to increase its lifetime