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