]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/promoted_const_fn_fail_deny_const_err.rs
Auto merge of #81132 - bugadani:map-prealloc, r=matthewjasper
[rust.git] / src / test / ui / consts / const-eval / promoted_const_fn_fail_deny_const_err.rs
1 #![feature(const_fn, const_fn_union)]
2
3 #![deny(const_err)]
4
5 #[repr(C)]
6 union Bar {
7     a: &'static u8,
8     b: usize,
9 }
10
11 const fn bar() -> u8 {
12     unsafe {
13         // This will error as long as this test is run on a system whose
14         // pointers need more than 8 bits.
15         Bar { a: &42 }.b as u8
16     }
17 }
18
19 fn main() {
20     // This will compile, but then hard-abort at runtime.
21     // FIXME(oli-obk): this should instead panic (not hard-abort) at runtime.
22     let x: &'static u8 = &(bar() + 1);
23     //~^ ERROR temporary value dropped while borrowed
24     let y = *x;
25     unreachable!();
26 }