Skip to content

Commit a3d987f

Browse files
committed
Fix ICE test
1 parent d761b18 commit a3d987f

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

tests/crashes/122548.rs

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//issue: rust-lang/rust#122548
2+
3+
// Strip out raw byte dumps to make comparison platform-independent:
4+
//@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)"
5+
//@ normalize-stderr-test "([0-9a-f][0-9a-f] |╾─*A(LLOC)?[0-9]+(\+[a-z0-9]+)?(<imm>)?─*╼ )+ *│.*" -> "HEX_DUMP"
6+
7+
#![feature(const_mut_refs)]
8+
#![feature(const_refs_to_static)]
9+
10+
use std::cell::UnsafeCell;
11+
12+
struct Meh {
13+
x: &'static UnsafeCell<i32>,
14+
}
15+
16+
const MUH: Meh = Meh { x: unsafe { &mut *(&READONLY as *const _ as *mut _) } };
17+
//~^ ERROR: it is undefined behavior to use this value
18+
19+
static READONLY: i32 = 0;
20+
21+
pub fn main() {}
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:16: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: $SIZE, align: $ALIGN) {
9+
HEX_DUMP
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)