]> git.proxmox.com Git - rustc.git/blame - src/test/ui/run-pass/consts/const-vec-of-fns.rs
New upstream version 1.30.0+dfsg1
[rustc.git] / src / test / ui / run-pass / consts / const-vec-of-fns.rs
CommitLineData
223e47cc
LB
1// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
b7449926 11// run-pass
c34b1796 12// pretty-expanded FIXME #23616
b7449926 13#![allow(non_upper_case_globals)]
c34b1796 14
223e47cc
LB
15/*!
16 * Try to double-check that static fns have the right size (with or
17 * without dummy env ptr, as appropriate) by iterating a size-2 array.
18 * If the static size differs from the runtime size, the second element
19 * should be read as a null or otherwise wrong pointer and crash.
20 */
21
22fn f() { }
1a4d82fc
JJ
23static bare_fns: &'static [fn()] = &[f, f];
24struct S<F: FnOnce()>(F);
25static mut closures: &'static mut [S<fn()>] = &mut [S(f as fn()), S(f as fn())];
223e47cc
LB
26
27pub fn main() {
1a4d82fc 28 unsafe {
85aaf69f
SL
29 for &bare_fn in bare_fns { bare_fn() }
30 for closure in &mut *closures {
1a4d82fc
JJ
31 let S(ref mut closure) = *closure;
32 (*closure)()
33 }
34 }
223e47cc 35}