diff --git a/src/librustc/ich/impls_mir.rs b/src/librustc/ich/impls_mir.rs index d82020f59a10e..6852e2c69618b 100644 --- a/src/librustc/ich/impls_mir.rs +++ b/src/librustc/ich/impls_mir.rs @@ -47,7 +47,6 @@ impl_stable_hash_for!(enum mir::BorrowKind { impl_stable_hash_for!(enum mir::UnsafetyViolationKind { General, GeneralAndConstFn, - GatedConstFnCall, ExternStatic(lint_node_id), BorrowPacked(lint_node_id), }); diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index dc14450e8d22d..120350a573b6e 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2792,9 +2792,6 @@ impl Location { #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub enum UnsafetyViolationKind { General, - /// Right now function calls to `const unsafe fn` are only permitted behind a feature gate - /// Also, even `const unsafe fn` need an `unsafe` block to do the allowed operations. - GatedConstFnCall, /// Permitted in const fn and regular fns GeneralAndConstFn, ExternStatic(ast::NodeId), diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index f6b7f817aad53..89d9c03f74e3e 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -23,7 +23,6 @@ use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext}; use syntax::ast; use syntax::symbol::Symbol; -use syntax::feature_gate::{emit_feature_err, GateIssue}; use std::ops::Bound; @@ -97,7 +96,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { if let hir::Unsafety::Unsafe = sig.unsafety() { self.require_unsafe("call to unsafe function", "consult the function's documentation for information on how to avoid \ - undefined behavior", UnsafetyViolationKind::GatedConstFnCall) + undefined behavior", UnsafetyViolationKind::GeneralAndConstFn) } } } @@ -325,11 +324,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { // compat lint violation.kind = UnsafetyViolationKind::General; }, - UnsafetyViolationKind::GatedConstFnCall => { - // safe code can't call unsafe const fns, this `UnsafetyViolationKind` - // is only relevant for `Safety::ExplicitUnsafe` in `unsafe const fn`s - violation.kind = UnsafetyViolationKind::General; - } } if !self.violations.contains(&violation) { self.violations.push(violation) @@ -346,19 +340,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { } // only some unsafety is allowed in const fn if self.min_const_fn { - let min_const_unsafe_fn = self.tcx.features().min_const_unsafe_fn; for violation in violations { match violation.kind { - UnsafetyViolationKind::GatedConstFnCall if min_const_unsafe_fn => { - // these function calls to unsafe functions are allowed - // if `#![feature(min_const_unsafe_fn)]` is active - }, - UnsafetyViolationKind::GatedConstFnCall => { - // without the feature gate, we report errors - if !self.violations.contains(&violation) { - self.violations.push(violation.clone()) - } - } // these unsafe things are stable in const fn UnsafetyViolationKind::GeneralAndConstFn => {}, // these things are forbidden in const fns @@ -620,16 +603,6 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { .note(&details.as_str()[..]) .emit(); } - UnsafetyViolationKind::GatedConstFnCall => { - emit_feature_err( - &tcx.sess.parse_sess, - "min_const_unsafe_fn", - source_info.span, - GateIssue::Language, - "calls to `const unsafe fn` in const fns are unstable", - ); - - } UnsafetyViolationKind::ExternStatic(lint_node_id) => { tcx.lint_node_note(SAFE_EXTERN_STATICS, lint_node_id, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 0d3de34fe6438..99a682832286e 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -273,7 +273,6 @@ #![feature(libc)] #![feature(link_args)] #![feature(linkage)] -#![cfg_attr(not(stage0), feature(min_const_unsafe_fn))] #![feature(needs_panic_runtime)] #![feature(never_type)] #![feature(nll)] diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 941a3a288da5c..2238e429a58e0 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -486,9 +486,6 @@ declare_features! ( // `extern crate self as foo;` puts local crate root into extern prelude under name `foo`. (active, extern_crate_self, "1.31.0", Some(56409), None), - - // Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions. - (active, min_const_unsafe_fn, "1.31.0", Some(55607), None), ); declare_features! ( @@ -694,6 +691,8 @@ declare_features! ( (accepted, underscore_imports, "1.33.0", Some(48216), None), // Allows `#[repr(packed(N))]` attribute on structs. (accepted, repr_packed, "1.33.0", Some(33158), None), + // Allows calling `const unsafe fn` inside `unsafe` blocks in `const fn` functions. + (accepted, min_const_unsafe_fn, "1.33.0", Some(55607), None), ); // If you change this, please modify `src/doc/unstable-book` as well. You must diff --git a/src/test/run-pass-fulldeps/newtype_index.rs b/src/test/run-pass-fulldeps/newtype_index.rs index 0fd7ccd55fb2d..3cd622a33b173 100644 --- a/src/test/run-pass-fulldeps/newtype_index.rs +++ b/src/test/run-pass-fulldeps/newtype_index.rs @@ -1,4 +1,4 @@ -#![feature(rustc_attrs, rustc_private, step_trait, min_const_unsafe_fn)] +#![feature(rustc_attrs, rustc_private, step_trait)] #[macro_use] extern crate rustc_data_structures; extern crate rustc_serialize; diff --git a/src/test/rustdoc/const-display.rs b/src/test/rustdoc/const-display.rs index 8ac0d07ceefe4..f38fab91de7c4 100644 --- a/src/test/rustdoc/const-display.rs +++ b/src/test/rustdoc/const-display.rs @@ -15,7 +15,6 @@ issue = "0")] #![feature(rustc_const_unstable, const_fn, foo, foo2)] -#![feature(min_const_unsafe_fn)] #![feature(staged_api)] // @has 'foo/fn.foo.html' '//pre' 'pub unsafe fn foo() -> u32' 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 92e99c6228a9b..da875fe7a6b77 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() -> *const T { 0 as *const T } const unsafe fn ret_null_mut_ptr_no_unsafe() -> *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::() } - //~^ ERROR calls to `const unsafe fn` in const fns are unstable } -const fn call_unsafe_generic_cell_const_fn() -> *const Vec> { +const fn call_unsafe_generic_cell_const_fn() + -> *const Vec> +{ unsafe { ret_null_mut_ptr_no_unsafe::>>() } - //~^ 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::() } +} +const unsafe fn call_unsafe_generic_cell_const_unsafe_fn() + -> *const Vec> +{ + unsafe { ret_null_mut_ptr_no_unsafe::>>() } +} + +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::() +} +const unsafe fn call_unsafe_generic_cell_const_unsafe_fn_immediate() + -> *const Vec> +{ + ret_null_mut_ptr_no_unsafe::>>() +} + +//------------------------------------------------------------------------------ +// 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 fafc89d149368..68b782bf0e7ea 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::() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +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::>>() } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +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 67a4820612642..0000000000000 --- 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 or the MIT license -// , 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() -> *const T { 0 as *const T } -const unsafe fn foo6() -> *mut T { 0 as *mut T } -const fn no_unsafe() { unsafe {} } - -const fn foo8() -> i32 { - unsafe { foo4() } -} -const fn foo9() -> *const String { - unsafe { foo5::() } -} -const fn foo10() -> *const Vec> { - unsafe { foo6::>>() } -} -const unsafe fn foo8_3() -> i32 { - unsafe { foo4() } -} -const unsafe fn foo9_3() -> *const String { - unsafe { foo5::() } -} -const unsafe fn foo10_3() -> *const Vec> { - unsafe { foo6::>>() } -} -const unsafe fn foo8_2() -> i32 { - foo4() -} -const unsafe fn foo9_2() -> *const String { - foo5::() -} -const unsafe fn foo10_2() -> *const Vec> { - foo6::>>() -} -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 63bf9a53e509c..0000000000000 --- 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 f559c23ff0f54..33fcea9818959 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 37be2889173f8..2a0ef0e6b9651 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 131bc97c85a2a..68205edd63bc9 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 0b58dc1294be0..6153301518563 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` | ^^^^^^^^^^^^