rust/tests/ui/consts/dangling_raw_ptr.rs
Oli Scherer 77fe9f0a72 Validate before reporting interning errors.
validation produces much higher quality errors and already handles most of the cases
2024-04-17 09:50:44 +00:00

30 lines
663 B
Rust

const FOO: *const u32 = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42;
&x
};
union Union {
ptr: *const u32,
}
const BAR: Union = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42;
Union { ptr: &x }
};
const BAZ: Union = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42_u32;
Union { ptr: &(&x as *const u32) as *const *const u32 as _ }
};
const FOOMP: *const u32 = {
//~^ ERROR encountered dangling pointer in final value of constant
let x = 42_u32;
&(&x as *const u32) as *const *const u32 as _
};
fn main() {}