1 // Copyright 2018 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.
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.
11 // gate-test-min_const_unsafe_fn
14 const unsafe fn foo4() -> i32 { 42 }
15 const unsafe fn foo5<T>() -> *const T { 0 as *const T }
16 const unsafe fn foo6<T>() -> *mut T { 0 as *mut T }
17 const fn no_unsafe() { unsafe {} }
20 const fn foo8() -> i32 {
21 unsafe { foo4() } //~ ERROR unsafe operations are not allowed in const fn
23 const fn foo9() -> *const String {
24 unsafe { foo5::<String>() } //~ ERROR unsafe operations are not allowed in const fn
26 const fn foo10() -> *const Vec<std::cell::Cell<u32>> {
27 unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } //~ ERROR not allowed in const fn
29 const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn
30 //~^ dereferencing raw pointers in constant functions
34 const unsafe fn no_union() {
35 union Foo { x: (), y: () }
36 Foo { x: () }.y //~ ERROR not allowed in const fn
37 //~^ unions in const fn