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