forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow calling
const unsafe fn
in const fn
behind a feature gate
- Loading branch information
Showing
9 changed files
with
194 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![feature(min_const_unsafe_fn)] | ||
|
||
// ok | ||
const unsafe fn foo4() -> i32 { 42 } | ||
const unsafe fn foo5<T>() -> *const T { 0 as *const T } | ||
const unsafe fn foo6<T>() -> *mut T { 0 as *mut T } | ||
const fn no_unsafe() { unsafe {} } | ||
|
||
const fn foo8() -> i32 { | ||
unsafe { foo4() } | ||
} | ||
const fn foo9() -> *const String { | ||
unsafe { foo5::<String>() } | ||
} | ||
const fn foo10() -> *const Vec<std::cell::Cell<u32>> { | ||
unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } | ||
} | ||
const unsafe fn foo8_3() -> i32 { | ||
unsafe { foo4() } | ||
} | ||
const unsafe fn foo9_3() -> *const String { | ||
unsafe { foo5::<String>() } | ||
} | ||
const unsafe fn foo10_3() -> *const Vec<std::cell::Cell<u32>> { | ||
unsafe { foo6::<Vec<std::cell::Cell<u32>>>() } | ||
} | ||
// not ok | ||
const unsafe fn foo8_2() -> i32 { | ||
foo4() //~ ERROR not allowed in const fn | ||
} | ||
const unsafe fn foo9_2() -> *const String { | ||
foo5::<String>() //~ ERROR not allowed in const fn | ||
} | ||
const unsafe fn foo10_2() -> *const Vec<std::cell::Cell<u32>> { | ||
foo6::<Vec<std::cell::Cell<u32>>>() //~ ERROR not allowed in const fn | ||
} | ||
const unsafe fn foo30_3(x: *mut usize) -> usize { *x } //~ ERROR not allowed in const fn | ||
//~^ dereferencing raw pointers in constant functions | ||
|
||
fn main() {} | ||
|
||
const unsafe fn no_union() { | ||
union Foo { x: (), y: () } | ||
Foo { x: () }.y //~ ERROR not allowed in const fn | ||
//~^ unions in const fn | ||
} |
Oops, something went wrong.