Skip to content

Commit 672b35c

Browse files
committed
More tests
1 parent 60329f7 commit 672b35c

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tests/ui/consts/dangling_raw_ptr.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const BAZ: Union = { //~ ERROR it is undefined behavior
2222
Union { ptr: &(&x as *const u32) as *const *const u32 as _ }
2323
};
2424

25-
fn main() {
26-
let x = FOO;
27-
let x = BAR;
28-
}
25+
const FOOMP: *const u32 = { //~ ERROR it is undefined behavior
26+
let x = 42_u32;
27+
&(&x as *const u32) as *const *const u32 as _
28+
};
29+
30+
fn main() {}

tests/ui/consts/dangling_raw_ptr.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ LL | const BAZ: Union = {
3131
HEX_DUMP
3232
}
3333

34-
error: aborting due to 3 previous errors
34+
error[E0080]: it is undefined behavior to use this value
35+
--> $DIR/dangling_raw_ptr.rs:25:1
36+
|
37+
LL | const FOOMP: *const u32 = {
38+
| ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<offset(0)>.<deref>: encountered a dangling reference (use-after-free)
39+
|
40+
= 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.
41+
= note: the raw bytes of the constant (size: $SIZE, align: $ALIGN) {
42+
HEX_DUMP
43+
}
44+
45+
error: aborting due to 4 previous errors
3546

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

0 commit comments

Comments
 (0)