]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-fn-not-safe-for-const.rs
Rollup merge of #64603 - gilescope:unused-lifetime-warning, r=matthewjasper
[rust.git] / src / test / ui / consts / const-fn-not-safe-for-const.rs
1 // Test that we can't call random fns in a const fn or do other bad things.
2
3 #![feature(const_fn, const_transmute)]
4
5 use std::mem::transmute;
6
7 fn random() -> u32 { 0 }
8
9 const fn sub(x: &u32) -> usize {
10     unsafe { transmute(x) }
11 }
12
13 const fn sub1() -> u32 {
14     random() //~ ERROR E0015
15 }
16
17 static Y: u32 = 0;
18
19 const fn get_Y() -> u32 {
20     Y
21         //~^ ERROR E0013
22 }
23
24 const fn get_Y_addr() -> &'static u32 {
25     &Y
26         //~^ ERROR E0013
27 }
28
29 const fn get() -> u32 {
30     let x = 22;
31     let y = 44;
32     x + y
33 }
34
35 fn main() {}