Skip to content

Commit acb817a

Browse files
committed
Fix ICE test
1 parent d761b18 commit acb817a

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

tests/crashes/122548.rs renamed to tests/ui/statics/mutable_memory_validation.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ known-bug: #122548
1+
//issue: rust-lang/rust#122548
22
#![feature(const_mut_refs)]
33
#![feature(const_refs_to_static)]
44

@@ -8,9 +8,8 @@ struct Meh {
88
x: &'static UnsafeCell<i32>,
99
}
1010

11-
const MUH: Meh = Meh {
12-
x: &mut *(&READONLY as *const _ as *mut _),
13-
};
11+
const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
12+
//~^ ERROR: it is undefined behavior to use this value
1413

1514
static READONLY: i32 = 0;
1615

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0080]: it is undefined behavior to use this value
2+
--> $DIR/mutable_memory_validation.rs:11:1
3+
|
4+
LL | const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
5+
| ^^^^^^^^^^^^^^ constructing invalid value at .x.<deref>: encountered `UnsafeCell` in read-only memory
6+
|
7+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8+
= note: the raw bytes of the constant (size: 8, align: 8) {
9+
╾ALLOC0<imm>╼ │ ╾──────╼
10+
}
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)