Skip to content

Commit 1d46ce5

Browse files
committed
Add regression test for issue 47215.
1 parent e6e4fe6 commit 1d46ce5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0507]: cannot move out of static item
2+
--> $DIR/issue-47215-ice-from-drop-elab.rs:17:21
3+
|
4+
LL | let mut x = X; //~ ERROR cannot move out of thread-local static item [E0507]
5+
| ^
6+
| |
7+
| cannot move out of static item
8+
| help: consider borrowing here: `&X`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0507`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// rust-lang/rust#47215: at one time, the compiler categorized
2+
// thread-local statics as a temporary rvalue, as a way to enforce
3+
// that they are only valid for a given lifetime.
4+
//
5+
// The problem with this is that you cannot move out of static items,
6+
// but you *can* move temporary rvalues. I.e., the categorization
7+
// above only solves half of the problem presented by thread-local
8+
// statics.
9+
10+
#![feature(thread_local)]
11+
12+
#[thread_local]
13+
static mut X: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
14+
15+
fn main() {
16+
unsafe {
17+
let mut x = X; //~ ERROR cannot move out of thread-local static item [E0507]
18+
let _y = x.get_mut();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0507]: cannot move out of thread-local static item
2+
--> $DIR/issue-47215-ice-from-drop-elab.rs:17:21
3+
|
4+
LL | let mut x = X; //~ ERROR cannot move out of thread-local static item [E0507]
5+
| ^
6+
| |
7+
| cannot move out of thread-local static item
8+
| help: consider using a reference instead: `&X`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)