Skip to content

Commit b1d4cbc

Browse files
committed
Add regression test
1 parent e05aae8 commit b1d4cbc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

tests/ui/consts/dangling_raw_ptr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ const FOO: *const u32 = { //~ ERROR it is undefined behavior
33
&x
44
};
55

6+
union Union {
7+
ptr: *const u32
8+
}
9+
10+
const BAR: Union = { //~ ERROR encountered dangling pointer in final value
11+
let x = 42;
12+
Union { ptr: &x }
13+
};
14+
615
fn main() {
716
let x = FOO;
17+
let x = BAR;
818
}

tests/ui/consts/dangling_raw_ptr.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ LL | const FOO: *const u32 = {
99
╾ALLOC0<imm>╼ │ ╾──────╼
1010
}
1111

12-
error: aborting due to 1 previous error
12+
error: encountered dangling pointer in final value of constant
13+
--> $DIR/dangling_raw_ptr.rs:10:1
14+
|
15+
LL | const BAR: Union = {
16+
| ^^^^^^^^^^^^^^^^
17+
18+
error: aborting due to 2 previous errors
1319

1420
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)