]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-vec-of-fns.rs
Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup
[rust.git] / src / test / ui / consts / const-vec-of-fns.rs
1 // run-pass
2 // pretty-expanded FIXME #23616
3 #![allow(non_upper_case_globals)]
4
5 /*!
6  * Try to double-check that static fns have the right size (with or
7  * without dummy env ptr, as appropriate) by iterating a size-2 array.
8  * If the static size differs from the runtime size, the second element
9  * should be read as a null or otherwise wrong pointer and crash.
10  */
11
12 fn f() { }
13 static bare_fns: &'static [fn()] = &[f, f];
14 struct S<F: FnOnce()>(F);
15 static mut closures: &'static mut [S<fn()>] = &mut [S(f as fn()), S(f as fn())];
16
17 pub fn main() {
18     unsafe {
19         for &bare_fn in bare_fns { bare_fn() }
20         for closure in &mut *closures {
21             let S(ref mut closure) = *closure;
22             (*closure)()
23         }
24     }
25 }