diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2018-12-23 23:09:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-23 23:09:14 +0100 |
| commit | 975a7f01f0df76190d4af3d01ddd8b0d82caa1e8 (patch) | |
| tree | 95ce350f74f1802b25e3cdcef283710e995a2391 /src/test/ui | |
| parent | e4826775f2a590c75659ba002b0461363ee4a386 (diff) | |
| parent | 7ae6fb215250d7515cc1ff7545c37d589104eda0 (diff) | |
| download | rust-975a7f01f0df76190d4af3d01ddd8b0d82caa1e8.tar.gz rust-975a7f01f0df76190d4af3d01ddd8b0d82caa1e8.zip | |
Rollup merge of #57067 - Centril:stabilize-min_const_unsafe_fn, r=oli-obk
Stabilize min_const_unsafe_fn in 1.33 Fixes #55607 r? @oli-obk
Diffstat (limited to 'src/test/ui')
8 files changed, 75 insertions, 146 deletions
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs index 92e99c6228a..da875fe7a6b 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.rs @@ -8,27 +8,62 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// gate-test-min_const_unsafe_fn +//------------------------------------------------------------------------------ +// OK +//------------------------------------------------------------------------------ -// ok const unsafe fn ret_i32_no_unsafe() -> i32 { 42 } const unsafe fn ret_null_ptr_no_unsafe<T>() -> *const T { 0 as *const T } const unsafe fn ret_null_mut_ptr_no_unsafe<T>() -> *mut T { 0 as *mut T } const fn no_unsafe() { unsafe {} } -// not ok const fn call_unsafe_const_fn() -> i32 { - unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable + unsafe { ret_i32_no_unsafe() } } const fn call_unsafe_generic_const_fn() -> *const String { unsafe { ret_null_ptr_no_unsafe::<String>() } - //~^ ERROR calls to `const unsafe fn` in const fns are unstable } -const fn call_unsafe_generic_cell_const_fn() -> *const Vec<std::cell::Cell<u32>> { +const fn call_unsafe_generic_cell_const_fn() + -> *const Vec<std::cell::Cell<u32>> +{ unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() } - //~^ ERROR calls to `const unsafe fn` in const fns } -const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } + +const unsafe fn call_unsafe_const_unsafe_fn() -> i32 { + unsafe { ret_i32_no_unsafe() } +} +const unsafe fn call_unsafe_generic_const_unsafe_fn() -> *const String { + unsafe { ret_null_ptr_no_unsafe::<String>() } +} +const unsafe fn call_unsafe_generic_cell_const_unsafe_fn() + -> *const Vec<std::cell::Cell<u32>> +{ + unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() } +} + +const unsafe fn call_unsafe_const_unsafe_fn_immediate() -> i32 { + ret_i32_no_unsafe() +} +const unsafe fn call_unsafe_generic_const_unsafe_fn_immediate() -> *const String { + ret_null_ptr_no_unsafe::<String>() +} +const unsafe fn call_unsafe_generic_cell_const_unsafe_fn_immediate() + -> *const Vec<std::cell::Cell<u32>> +{ + ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() +} + +//------------------------------------------------------------------------------ +// NOT OK +//------------------------------------------------------------------------------ + +const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe +//~^ dereferencing raw pointers in constant functions + +const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x } +//~^ dereferencing raw pointers in constant functions + +const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x } //~^ dereferencing raw pointers in constant functions fn main() {} diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr index fafc89d1493..68b782bf0e7 100644 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe.stderr @@ -1,43 +1,44 @@ error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) - --> $DIR/min_const_fn_unsafe.rs:31:59 + --> $DIR/min_const_fn_unsafe.rs:60:77 | -LL | const unsafe fn deref_forbidden(x: *mut usize) -> usize { *x } - | ^^ +LL | const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe + | ^^^ | = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable -error[E0658]: unions in const fn are unstable (see issue #51909) - --> $DIR/min_const_fn_unsafe.rs:38:5 +error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) + --> $DIR/min_const_fn_unsafe.rs:63:70 | -LL | Foo { x: () }.y - | ^^^^^^^^^^^^^^^ +LL | const unsafe fn bad_const_unsafe_deref_raw(x: *mut usize) -> usize { *x } + | ^^ | - = help: add #![feature(const_fn_union)] to the crate attributes to enable + = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable -error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607) - --> $DIR/min_const_fn_unsafe.rs:21:14 +error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) + --> $DIR/min_const_fn_unsafe.rs:66:83 | -LL | unsafe { ret_i32_no_unsafe() } //~ ERROR calls to `const unsafe fn` in const fns are unstable - | ^^^^^^^^^^^^^^^^^^^ +LL | const unsafe fn bad_const_unsafe_deref_raw_ref(x: *mut usize) -> &'static usize { &*x } + | ^^^ | - = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable + = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable -error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607) - --> $DIR/min_const_fn_unsafe.rs:24:14 +error[E0658]: unions in const fn are unstable (see issue #51909) + --> $DIR/min_const_fn_unsafe.rs:73:5 | -LL | unsafe { ret_null_ptr_no_unsafe::<String>() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | Foo { x: () }.y + | ^^^^^^^^^^^^^^^ | - = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable + = help: add #![feature(const_fn_union)] to the crate attributes to enable -error[E0658]: calls to `const unsafe fn` in const fns are unstable (see issue #55607) - --> $DIR/min_const_fn_unsafe.rs:28:14 +error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block + --> $DIR/min_const_fn_unsafe.rs:60:77 | -LL | unsafe { ret_null_mut_ptr_no_unsafe::<Vec<std::cell::Cell<u32>>>() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | const fn bad_const_fn_deref_raw(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe + | ^^^ dereference of raw pointer | - = help: add #![feature(min_const_unsafe_fn)] to the crate attributes to enable + = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0658`. +Some errors occurred: E0133, E0658. +For more information about an error, try `rustc --explain E0133`. diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs deleted file mode 100644 index 67a48206126..00000000000 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.rs +++ /dev/null @@ -1,61 +0,0 @@ -// 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>>>() } -} -const unsafe fn foo8_2() -> i32 { - foo4() -} -const unsafe fn foo9_2() -> *const String { - foo5::<String>() -} -const unsafe fn foo10_2() -> *const Vec<std::cell::Cell<u32>> { - foo6::<Vec<std::cell::Cell<u32>>>() -} -const unsafe fn foo30_3(x: *mut usize) -> usize { *x } -//~^ dereferencing raw pointers in constant functions - -const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } -//~^ dereferencing raw pointers in constant functions - -const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe -//~^ dereferencing raw pointers in constant functions - -fn main() {} - -const unsafe fn no_union() { - union Foo { x: (), y: () } - Foo { x: () }.y - //~^ unions in const fn -} diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr deleted file mode 100644 index 63bf9a53e50..00000000000 --- a/src/test/ui/consts/min_const_fn/min_const_fn_unsafe_feature_gate.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) - --> $DIR/min_const_fn_unsafe_feature_gate.rs:46:51 - | -LL | const unsafe fn foo30_3(x: *mut usize) -> usize { *x } - | ^^ - | - = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable - -error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) - --> $DIR/min_const_fn_unsafe_feature_gate.rs:49:60 - | -LL | const unsafe fn foo30_4(x: *mut usize) -> &'static usize { &*x } - | ^^^ - | - = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable - -error[E0658]: dereferencing raw pointers in constant functions is unstable (see issue #51911) - --> $DIR/min_const_fn_unsafe_feature_gate.rs:52:62 - | -LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe - | ^^^ - | - = help: add #![feature(const_raw_ptr_deref)] to the crate attributes to enable - -error[E0658]: unions in const fn are unstable (see issue #51909) - --> $DIR/min_const_fn_unsafe_feature_gate.rs:59:5 - | -LL | Foo { x: () }.y - | ^^^^^^^^^^^^^^^ - | - = help: add #![feature(const_fn_union)] to the crate attributes to enable - -error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block - --> $DIR/min_const_fn_unsafe_feature_gate.rs:52:62 - | -LL | const fn foo30_5(x: *mut usize) -> &'static usize { unsafe { &*x } } //~ is unsafe - | ^^^ dereference of raw pointer - | - = note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior - -error: aborting due to 5 previous errors - -Some errors occurred: E0133, E0658. -For more information about an error, try `rustc --explain E0133`. diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs index f559c23ff0f..33fcea98189 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.rs @@ -14,7 +14,6 @@ issue = "0")] #![feature(rustc_const_unstable, const_fn, foo, foo2)] -#![feature(min_const_unsafe_fn)] #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr index 37be2889173..2a0ef0e6b96 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability.stderr @@ -1,23 +1,23 @@ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:26:41 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:25:41 | LL | const unsafe fn bar() -> u32 { unsafe { foo() } } //~ ERROR can only call other `min_const_fn` | ^^^^^ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:33:42 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:32:42 | LL | const unsafe fn bar2() -> u32 { unsafe { foo2() } } //~ ERROR can only call other `min_const_fn` | ^^^^^^ error: only int, `bool` and `char` operations are stable in const fn - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:37:33 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:36:33 | LL | const unsafe fn bar3() -> u32 { (5f32 + 6f32) as u32 } //~ ERROR only int, `bool` and `char` op | ^^^^^^^^^^^^^ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability.rs:45:48 + --> $DIR/min_const_unsafe_fn_libstd_stability.rs:44:48 | LL | const unsafe fn bar2_gated() -> u32 { unsafe { foo2_gated() } } //~ ERROR can only call other | ^^^^^^^^^^^^ diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs index 131bc97c85a..68205edd63b 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.rs @@ -14,7 +14,6 @@ issue = "0")] #![feature(rustc_const_unstable, const_fn, foo, foo2)] -#![feature(min_const_unsafe_fn)] #![feature(staged_api)] #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr index 0b58dc1294b..61533015185 100644 --- a/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr +++ b/src/test/ui/consts/min_const_fn/min_const_unsafe_fn_libstd_stability2.stderr @@ -1,17 +1,17 @@ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:26:32 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:25:32 | LL | const unsafe fn bar() -> u32 { foo() } //~ ERROR can only call other `min_const_fn` | ^^^^^ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:33:33 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:32:33 | LL | const unsafe fn bar2() -> u32 { foo2() } //~ ERROR can only call other `min_const_fn` | ^^^^^^ error: can only call other `min_const_fn` within a `min_const_fn` - --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:41:39 + --> $DIR/min_const_unsafe_fn_libstd_stability2.rs:40:39 | LL | const unsafe fn bar2_gated() -> u32 { foo2_gated() } //~ ERROR can only call other `min_const_fn` | ^^^^^^^^^^^^ |
