about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-04-24 23:16:03 +0000
committerbors <bors@rust-lang.org>2021-04-24 23:16:03 +0000
commitb56b175c6c3d77f66793b2062b6325f822c87136 (patch)
tree330de8b31a7fff50d3d8a253decc30cd3f4977c9
parent42816d61ead7e46d462df997958ccfd514f8c21c (diff)
parent49054c3617bb04ba4f108ab7a5fbe6cda74bcbd3 (diff)
downloadrust-b56b175c6c3d77f66793b2062b6325f822c87136.tar.gz
rust-b56b175c6c3d77f66793b2062b6325f822c87136.zip
Auto merge of #84310 - RalfJung:const-fn-feature-flags, r=oli-obk
further split up const_fn feature flag

This continues the work on splitting up `const_fn` into separate feature flags:
* `const_fn_trait_bound` for `const fn` with trait bounds
* `const_fn_unsize` for unsizing coercions in `const fn` (looks like only `dyn` unsizing is still guarded here)

I don't know if there are even any things left that `const_fn` guards... at least libcore and liballoc do not need it any more.

`@oli-obk` are you currently able to do reviews?
-rw-r--r--compiler/rustc_ast/src/lib.rs3
-rw-r--r--compiler/rustc_error_codes/src/error_codes.rs2
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0723.md20
-rw-r--r--compiler/rustc_feature/src/active.rs6
-rw-r--r--compiler/rustc_hir/src/lib.rs1
-rw-r--r--compiler/rustc_index/src/lib.rs1
-rw-r--r--compiler/rustc_infer/src/lib.rs1
-rw-r--r--compiler/rustc_middle/src/lib.rs1
-rw-r--r--compiler/rustc_mir/src/lib.rs1
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/ops.rs40
-rw-r--r--compiler/rustc_mir/src/transform/check_consts/validation.rs14
-rw-r--r--compiler/rustc_mir_build/src/lib.rs1
-rw-r--r--compiler/rustc_passes/src/lib.rs1
-rw-r--r--compiler/rustc_query_system/src/lib.rs1
-rw-r--r--compiler/rustc_span/src/lib.rs1
-rw-r--r--compiler/rustc_span/src/symbol.rs2
-rw-r--r--compiler/rustc_target/src/lib.rs1
-rw-r--r--library/alloc/src/lib.rs3
-rw-r--r--library/core/src/lib.rs3
-rwxr-xr-xsrc/ci/pgo.sh2
-rw-r--r--src/test/ui/consts/const-eval/issue-49296.rs2
-rw-r--r--src/test/ui/consts/const-fn.rs3
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.gated.stderr8
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.rs17
-rw-r--r--src/test/ui/consts/const_fn_trait_bound.stock.stderr30
-rw-r--r--src/test/ui/consts/const_fn_unsize.gated.stderr8
-rw-r--r--src/test/ui/consts/const_fn_unsize.rs16
-rw-r--r--src/test/ui/consts/const_fn_unsize.stock.stderr12
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn.stderr56
-rw-r--r--src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr12
-rw-r--r--src/test/ui/consts/unsizing-cast-non-null.stderr8
-rw-r--r--src/test/ui/consts/unstable-const-fn-in-libcore.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs2
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/stability.stderr3
37 files changed, 176 insertions, 114 deletions
diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs
index 1e6da044ec0..ffec28a395f 100644
--- a/compiler/rustc_ast/src/lib.rs
+++ b/compiler/rustc_ast/src/lib.rs
@@ -10,7 +10,8 @@
 )]
 #![feature(box_syntax)]
 #![feature(box_patterns)]
-#![feature(const_fn)] // For the `transmute` in `P::new`
+#![cfg_attr(bootstrap, feature(const_fn))] // For the `transmute` in `P::new`
+#![cfg_attr(not(bootstrap), feature(const_fn_unsize))] // For the `transmute` in `P::new`
 #![feature(const_fn_transmute)]
 #![feature(const_panic)]
 #![feature(crate_visibility_modifier)]
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs
index 4b529734328..41a1fa488d3 100644
--- a/compiler/rustc_error_codes/src/error_codes.rs
+++ b/compiler/rustc_error_codes/src/error_codes.rs
@@ -416,7 +416,6 @@ E0716: include_str!("./error_codes/E0716.md"),
 E0718: include_str!("./error_codes/E0718.md"),
 E0719: include_str!("./error_codes/E0719.md"),
 E0720: include_str!("./error_codes/E0720.md"),
-E0723: include_str!("./error_codes/E0723.md"),
 E0724: include_str!("./error_codes/E0724.md"),
 E0725: include_str!("./error_codes/E0725.md"),
 E0727: include_str!("./error_codes/E0727.md"),
@@ -636,6 +635,7 @@ E0781: include_str!("./error_codes/E0781.md"),
     E0717, // rustc_promotable without stability attribute
 //  E0721, // `await` keyword
     E0722, // Malformed `#[optimize]` attribute
+//    E0723, unstable feature in `const` context
     E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
 //  E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
     E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
diff --git a/compiler/rustc_error_codes/src/error_codes/E0723.md b/compiler/rustc_error_codes/src/error_codes/E0723.md
deleted file mode 100644
index bc224421915..00000000000
--- a/compiler/rustc_error_codes/src/error_codes/E0723.md
+++ /dev/null
@@ -1,20 +0,0 @@
-An unstable feature in `const` contexts was used.
-
-Erroneous code example:
-
-```compile_fail,E0723
-const fn foo<T: Copy>(_: T) { // error!
-   // ...
-}
-```
-
-To enable this feature on a nightly version of rustc, add the `const_fn`
-feature flag:
-
-```
-#![feature(const_fn)]
-
-const fn foo<T: Copy>(_: T) { // ok!
-   // ...
-}
-```
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index eb143e5bac2..72babb7aec1 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -645,6 +645,12 @@ declare_features! (
     /// Allows `extern "wasm" fn`
     (active, wasm_abi, "1.53.0", Some(83788), None),
 
+    /// Allows trait bounds in `const fn`.
+    (active, const_fn_trait_bound, "1.53.0", Some(57563), None),
+
+    /// Allows unsizing coercions in `const fn`.
+    (active, const_fn_unsize, "1.53.0", Some(64992), None),
+
     // -------------------------------------------------------------------------
     // feature-group-end: actual feature gates
     // -------------------------------------------------------------------------
diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs
index 36a30900fb2..65c99535c4e 100644
--- a/compiler/rustc_hir/src/lib.rs
+++ b/compiler/rustc_hir/src/lib.rs
@@ -3,7 +3,6 @@
 //! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
 
 #![feature(crate_visibility_modifier)]
-#![feature(const_fn)] // For the unsizing cast on `&[]`
 #![feature(const_panic)]
 #![feature(extended_key_value_attributes)]
 #![feature(in_band_lifetimes)]
diff --git a/compiler/rustc_index/src/lib.rs b/compiler/rustc_index/src/lib.rs
index 3ced3920cfd..9c306d02512 100644
--- a/compiler/rustc_index/src/lib.rs
+++ b/compiler/rustc_index/src/lib.rs
@@ -1,5 +1,4 @@
 #![feature(allow_internal_unstable)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(extend_one)]
 #![feature(iter_zip)]
diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs
index 25a262d7e48..15b4a7ed207 100644
--- a/compiler/rustc_infer/src/lib.rs
+++ b/compiler/rustc_infer/src/lib.rs
@@ -16,7 +16,6 @@
 #![feature(bool_to_option)]
 #![feature(box_patterns)]
 #![feature(box_syntax)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(extend_one)]
 #![feature(iter_zip)]
diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs
index 1db03e9165b..45ea07a3db6 100644
--- a/compiler/rustc_middle/src/lib.rs
+++ b/compiler/rustc_middle/src/lib.rs
@@ -29,7 +29,6 @@
 #![feature(bool_to_option)]
 #![feature(box_patterns)]
 #![feature(box_syntax)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(core_intrinsics)]
 #![feature(discriminant_kind)]
diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs
index b0db4f9e649..783aa9465c3 100644
--- a/compiler/rustc_mir/src/lib.rs
+++ b/compiler/rustc_mir/src/lib.rs
@@ -12,7 +12,6 @@ Rust MIR: a lowered representation of Rust.
 #![feature(bool_to_option)]
 #![feature(box_patterns)]
 #![feature(box_syntax)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(crate_visibility_modifier)]
 #![feature(decl_macro)]
diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs
index a18c1f74524..ffeaaf60a30 100644
--- a/compiler/rustc_mir/src/transform/check_consts/ops.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs
@@ -540,12 +540,17 @@ impl NonConstOp for UnionAccess {
 pub struct UnsizingCast;
 impl NonConstOp for UnsizingCast {
     fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
-        mcf_status_in_item(ccx)
+        if ccx.const_kind() != hir::ConstContext::ConstFn {
+            Status::Allowed
+        } else {
+            Status::Unstable(sym::const_fn_unsize)
+        }
     }
 
     fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
-        mcf_build_error(
-            ccx,
+        feature_err(
+            &ccx.tcx.sess.parse_sess,
+            sym::const_fn_unsize,
             span,
             "unsizing casts to types besides slices are not allowed in const fn",
         )
@@ -642,12 +647,17 @@ pub mod ty {
         }
 
         fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
-            mcf_status_in_item(ccx)
+            if ccx.const_kind() != hir::ConstContext::ConstFn {
+                Status::Allowed
+            } else {
+                Status::Unstable(sym::const_fn_trait_bound)
+            }
         }
 
         fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
-            mcf_build_error(
-                ccx,
+            feature_err(
+                &ccx.tcx.sess.parse_sess,
+                sym::const_fn_trait_bound,
                 span,
                 "trait bounds other than `Sized` on const fn parameters are unstable",
             )
@@ -672,21 +682,3 @@ pub mod ty {
         }
     }
 }
-
-fn mcf_status_in_item(ccx: &ConstCx<'_, '_>) -> Status {
-    if ccx.const_kind() != hir::ConstContext::ConstFn {
-        Status::Allowed
-    } else {
-        Status::Unstable(sym::const_fn)
-    }
-}
-
-fn mcf_build_error(ccx: &ConstCx<'_, 'tcx>, span: Span, msg: &str) -> DiagnosticBuilder<'tcx> {
-    let mut err = struct_span_err!(ccx.tcx.sess, span, E0723, "{}", msg);
-    err.note(
-        "see issue #57563 <https://github.com/rust-lang/rust/issues/57563> \
-             for more information",
-    );
-    err.help("add `#![feature(const_fn)]` to the crate attributes to enable");
-    err
-}
diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs
index ce5e41d3e7c..cf7d404a077 100644
--- a/compiler/rustc_mir/src/transform/check_consts/validation.rs
+++ b/compiler/rustc_mir/src/transform/check_consts/validation.rs
@@ -1,6 +1,6 @@
 //! The `Visitor` responsible for actually checking a `mir::Body` for invalid operations.
 
-use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
+use rustc_errors::{Applicability, Diagnostic, ErrorReported};
 use rustc_hir::def_id::DefId;
 use rustc_hir::{self as hir, HirId, LangItem};
 use rustc_index::bit_set::BitSet;
@@ -234,13 +234,11 @@ impl Validator<'mir, 'tcx> {
             if self.is_const_stable_const_fn() {
                 let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
                 if crate::const_eval::is_parent_const_impl_raw(tcx, hir_id) {
-                    struct_span_err!(
-                        self.ccx.tcx.sess,
-                        self.span,
-                        E0723,
-                        "trait methods cannot be stable const fn"
-                    )
-                    .emit();
+                    self.ccx
+                        .tcx
+                        .sess
+                        .struct_span_err(self.span, "trait methods cannot be stable const fn")
+                        .emit();
                 }
             }
 
diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs
index 23bc1da09b5..da9a0b08e86 100644
--- a/compiler/rustc_mir_build/src/lib.rs
+++ b/compiler/rustc_mir_build/src/lib.rs
@@ -4,7 +4,6 @@
 #![feature(array_windows)]
 #![feature(box_patterns)]
 #![feature(box_syntax)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(control_flow_enum)]
 #![feature(crate_visibility_modifier)]
diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs
index 933e8ad1d72..0be7ef7e12a 100644
--- a/compiler/rustc_passes/src/lib.rs
+++ b/compiler/rustc_passes/src/lib.rs
@@ -5,7 +5,6 @@
 //! This API is completely unstable and subject to change.
 
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(crate_visibility_modifier)]
 #![feature(in_band_lifetimes)]
diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs
index 071144f38e7..be72baefb9e 100644
--- a/compiler/rustc_query_system/src/lib.rs
+++ b/compiler/rustc_query_system/src/lib.rs
@@ -1,5 +1,4 @@
 #![feature(bool_to_option)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(core_intrinsics)]
 #![feature(drain_filter)]
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 6f6ff37c525..d30236ec3ec 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -16,7 +16,6 @@
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![feature(array_windows)]
 #![feature(crate_visibility_modifier)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(negative_impls)]
 #![feature(nll)]
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 4a1af4a2945..fdfd226b425 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -382,8 +382,10 @@ symbols! {
         const_fn,
         const_fn_floating_point_arithmetic,
         const_fn_fn_ptr_basics,
+        const_fn_trait_bound,
         const_fn_transmute,
         const_fn_union,
+        const_fn_unsize,
         const_generic_defaults,
         const_generics,
         const_generics_defaults,
diff --git a/compiler/rustc_target/src/lib.rs b/compiler/rustc_target/src/lib.rs
index b54764b9e32..67025388747 100644
--- a/compiler/rustc_target/src/lib.rs
+++ b/compiler/rustc_target/src/lib.rs
@@ -9,7 +9,6 @@
 
 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
 #![feature(bool_to_option)]
-#![feature(const_fn)]
 #![feature(const_panic)]
 #![feature(nll)]
 #![feature(never_type)]
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index 14cb1d3b405..3a5dcec668f 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -89,7 +89,8 @@
 #![feature(cfg_target_has_atomic)]
 #![feature(coerce_unsized)]
 #![feature(const_btree_new)]
-#![feature(const_fn)]
+#![cfg_attr(bootstrap, feature(const_fn))]
+#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
 #![feature(cow_is_borrowed)]
 #![feature(const_cow_is_borrowed)]
 #![feature(destructuring_assignment)]
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index 9f8a6f3d3b5..0e2c140c367 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -81,11 +81,12 @@
 #![feature(const_refs_to_cell)]
 #![feature(const_panic)]
 #![feature(const_pin)]
-#![feature(const_fn)]
+#![cfg_attr(bootstrap, feature(const_fn))]
 #![feature(const_fn_union)]
 #![feature(const_impl_trait)]
 #![feature(const_fn_floating_point_arithmetic)]
 #![feature(const_fn_fn_ptr_basics)]
+#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
 #![feature(const_option)]
 #![feature(const_precise_live_drops)]
 #![feature(const_ptr_offset)]
diff --git a/src/ci/pgo.sh b/src/ci/pgo.sh
index 95cf1183fc1..ad2a8c771de 100755
--- a/src/ci/pgo.sh
+++ b/src/ci/pgo.sh
@@ -12,7 +12,7 @@ RUSTC_BOOTSTRAP=1 ./build/$PGO_HOST/stage2/bin/rustc --edition=2018 \
 
 # Download and build a single-file stress test benchmark on perf.rust-lang.org.
 function pgo_perf_benchmark {
-    local PERF=e095f5021bf01cf3800f50b3a9f14a9683eb3e4e
+    local PERF=9442def56a39d742bf27ebcc3e0614cf117e1bc2
     local github_prefix=https://raw.githubusercontent.com/rust-lang/rustc-perf/$PERF
     local name=$1
     curl -o /tmp/$name.rs $github_prefix/collector/benchmarks/$name/src/lib.rs
diff --git a/src/test/ui/consts/const-eval/issue-49296.rs b/src/test/ui/consts/const-eval/issue-49296.rs
index 9fd9e8f3647..f2d9758b8dc 100644
--- a/src/test/ui/consts/const-eval/issue-49296.rs
+++ b/src/test/ui/consts/const-eval/issue-49296.rs
@@ -1,7 +1,7 @@
 // issue-49296: Unsafe shenigans in constants can result in missing errors
 
-#![feature(const_fn)]
 #![feature(const_fn_union)]
+#![feature(const_fn_trait_bound)]
 
 const unsafe fn transmute<T: Copy, U: Copy>(t: T) -> U {
     #[repr(C)]
diff --git a/src/test/ui/consts/const-fn.rs b/src/test/ui/consts/const-fn.rs
index 7b924aa46aa..1928c51885e 100644
--- a/src/test/ui/consts/const-fn.rs
+++ b/src/test/ui/consts/const-fn.rs
@@ -3,7 +3,8 @@
 
 // A very basic test of const fn functionality.
 
-#![feature(const_fn, const_indexing)]
+#![feature(const_indexing)]
+#![feature(const_fn_trait_bound)]
 
 const fn add(x: u32, y: u32) -> u32 {
     x + y
diff --git a/src/test/ui/consts/const_fn_trait_bound.gated.stderr b/src/test/ui/consts/const_fn_trait_bound.gated.stderr
new file mode 100644
index 00000000000..ded05cb17c5
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.gated.stderr
@@ -0,0 +1,8 @@
+error: fatal error triggered by #[rustc_error]
+  --> $DIR/const_fn_trait_bound.rs:17:1
+   |
+LL | fn main() {}
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/consts/const_fn_trait_bound.rs b/src/test/ui/consts/const_fn_trait_bound.rs
new file mode 100644
index 00000000000..b1ef820d827
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.rs
@@ -0,0 +1,17 @@
+// gate-test-const_fn_trait_bound
+
+// revisions: stock gated
+
+#![feature(rustc_attrs)]
+#![cfg_attr(gated, feature(const_fn_trait_bound))]
+
+const fn test1<T: std::ops::Add>() {}
+//[stock]~^ trait bounds
+const fn test2(_x: &dyn Send) {}
+//[stock]~^ trait bounds
+const fn test3() -> &'static dyn Send { loop {} }
+//[stock]~^ trait bounds
+
+
+#[rustc_error]
+fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
diff --git a/src/test/ui/consts/const_fn_trait_bound.stock.stderr b/src/test/ui/consts/const_fn_trait_bound.stock.stderr
new file mode 100644
index 00000000000..2ad45f3afde
--- /dev/null
+++ b/src/test/ui/consts/const_fn_trait_bound.stock.stderr
@@ -0,0 +1,30 @@
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:8:16
+   |
+LL | const fn test1<T: std::ops::Add>() {}
+   |                ^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:10:16
+   |
+LL | const fn test2(_x: &dyn Send) {}
+   |                ^^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
+  --> $DIR/const_fn_trait_bound.rs:12:21
+   |
+LL | const fn test3() -> &'static dyn Send { loop {} }
+   |                     ^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/consts/const_fn_unsize.gated.stderr b/src/test/ui/consts/const_fn_unsize.gated.stderr
new file mode 100644
index 00000000000..8a65c274ca9
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.gated.stderr
@@ -0,0 +1,8 @@
+error: fatal error triggered by #[rustc_error]
+  --> $DIR/const_fn_unsize.rs:16:1
+   |
+LL | fn main() {}
+   | ^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/consts/const_fn_unsize.rs b/src/test/ui/consts/const_fn_unsize.rs
new file mode 100644
index 00000000000..0cab3b0a031
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.rs
@@ -0,0 +1,16 @@
+// gate-test-const_fn_unsize
+
+// revisions: stock gated
+
+#![feature(rustc_attrs)]
+#![cfg_attr(gated, feature(const_fn_unsize))]
+
+use std::ptr::NonNull;
+
+const fn test() {
+    let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
+    //[stock]~^ unsizing cast
+}
+
+#[rustc_error]
+fn main() {} //[gated]~ fatal error triggered by #[rustc_error]
diff --git a/src/test/ui/consts/const_fn_unsize.stock.stderr b/src/test/ui/consts/const_fn_unsize.stock.stderr
new file mode 100644
index 00000000000..cc746d4f175
--- /dev/null
+++ b/src/test/ui/consts/const_fn_unsize.stock.stderr
@@ -0,0 +1,12 @@
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
+  --> $DIR/const_fn_unsize.rs:11:14
+   |
+LL |     let _x = NonNull::<[i32; 0]>::dangling() as NonNull<[i32]>;
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
index ee5434b147b..e6ce7e12520 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn.stderr
+++ b/src/test/ui/consts/min_const_fn/min_const_fn.stderr
@@ -130,23 +130,23 @@ LL |     const fn get_mut_sq(&mut self) -> &mut T { &mut self.0 }
    = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:84:16
    |
 LL | const fn foo11<T: std::fmt::Display>(t: T) -> T { t }
    |                ^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:86:18
    |
 LL | const fn foo11_2<T: Send>(t: T) -> T { t }
    |                  ^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
 error[E0013]: constant functions cannot refer to statics
   --> $DIR/min_const_fn.rs:90:27
@@ -209,41 +209,41 @@ LL | const fn inc(x: &mut i32) { *x += 1 }
    = note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
    = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:110:6
    |
 LL | impl<T: std::fmt::Debug> Foo<T> {
    |      ^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:115:6
    |
 LL | impl<T: std::fmt::Debug + Sized> Foo<T> {
    |      ^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:120:6
    |
 LL | impl<T: Sync + Sized> Foo<T> {
    |      ^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:126:34
    |
 LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
    |                                  ^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/min_const_fn.rs:126:19
@@ -253,14 +253,14 @@ LL | const fn no_apit2(_x: AlanTuring<impl std::fmt::Debug>) {}
    |                   |
    |                   constant functions cannot evaluate destructors
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:129:22
    |
 LL | const fn no_apit(_x: impl std::fmt::Debug) {}
    |                      ^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
 error[E0493]: destructors cannot be evaluated at compile-time
   --> $DIR/min_const_fn.rs:129:18
@@ -270,50 +270,50 @@ LL | const fn no_apit(_x: impl std::fmt::Debug) {}
    |                  |
    |                  constant functions cannot evaluate destructors
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:132:23
    |
 LL | const fn no_dyn_trait(_x: &dyn std::fmt::Debug) {}
    |                       ^^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn.rs:134:32
    |
 LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
   --> $DIR/min_const_fn.rs:134:63
    |
 LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
    |                                                               ^^^
    |
-   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
 
-error[E0723]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
   --> $DIR/min_const_fn.rs:134:63
    |
 LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
    |                                                               ^^^
    |
-   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
 
-error[E0723]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
   --> $DIR/min_const_fn.rs:141:42
    |
 LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
    |                                          ^^^
    |
-   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
 
 error[E0658]: function pointers cannot appear in constant functions
   --> $DIR/min_const_fn.rs:144:21
@@ -344,5 +344,5 @@ LL | const fn no_fn_ptrs2() -> fn() { fn foo() {} foo }
 
 error: aborting due to 39 previous errors
 
-Some errors have detailed explanations: E0013, E0493, E0658, E0723.
+Some errors have detailed explanations: E0013, E0493, E0658.
 For more information about an error, try `rustc --explain E0013`.
diff --git a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
index 1394db591ca..cf635d65699 100644
--- a/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
+++ b/src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
@@ -1,21 +1,21 @@
-error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
+error[E0658]: trait bounds other than `Sized` on const fn parameters are unstable
   --> $DIR/min_const_fn_dyn.rs:9:5
    |
 LL |     x.0.field;
    |     ^^^^^^^^^
    |
    = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = help: add `#![feature(const_fn_trait_bound)]` to the crate attributes to enable
 
-error[E0723]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
   --> $DIR/min_const_fn_dyn.rs:12:66
    |
 LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
    |                                                                  ^^
    |
-   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0723`.
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/consts/unsizing-cast-non-null.stderr b/src/test/ui/consts/unsizing-cast-non-null.stderr
index dc08ccd02b6..79691cddfb4 100644
--- a/src/test/ui/consts/unsizing-cast-non-null.stderr
+++ b/src/test/ui/consts/unsizing-cast-non-null.stderr
@@ -1,12 +1,12 @@
-error[E0723]: unsizing casts to types besides slices are not allowed in const fn
+error[E0658]: unsizing casts to types besides slices are not allowed in const fn
   --> $DIR/unsizing-cast-non-null.rs:6:5
    |
 LL |     NonNull::<[T; 0]>::dangling()
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
-   = help: add `#![feature(const_fn)]` to the crate attributes to enable
+   = note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
+   = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
 
 error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0723`.
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/consts/unstable-const-fn-in-libcore.rs b/src/test/ui/consts/unstable-const-fn-in-libcore.rs
index 43951c6854b..2fbbbbffac4 100644
--- a/src/test/ui/consts/unstable-const-fn-in-libcore.rs
+++ b/src/test/ui/consts/unstable-const-fn-in-libcore.rs
@@ -6,7 +6,7 @@
 #![stable(feature = "core", since = "1.6.0")]
 #![feature(rustc_const_unstable)]
 #![feature(staged_api)]
-#![feature(const_fn)]
+#![feature(const_fn_trait_bound)]
 
 enum Opt<T> {
     Some(T),
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs
index 6a511f4ed3e..c37990b1af3 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-chain.rs
@@ -2,8 +2,8 @@
 
 // check-pass
 
-#![feature(const_fn)]
 #![feature(const_trait_impl)]
+#![feature(const_fn_trait_bound)]
 #![allow(incomplete_features)]
 
 struct S;
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs
index b39d27779f4..d553b2ab8ec 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-dup-bound.rs
@@ -1,8 +1,8 @@
 // check-pass
 
-#![feature(const_fn)]
 #![feature(const_trait_impl)]
 #![feature(const_trait_bound_opt_out)]
+#![feature(const_fn_trait_bound)]
 #![allow(incomplete_features)]
 
 struct S;
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs
index e968e6ec7bb..74b0d5fbe47 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-pass.rs
@@ -2,8 +2,8 @@
 
 // check-pass
 
-#![feature(const_fn)]
 #![feature(const_trait_impl)]
+#![feature(const_fn_trait_bound)]
 #![allow(incomplete_features)]
 
 struct S;
diff --git a/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs b/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs
index 7829ffe2a38..d3680820312 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs
+++ b/src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs
@@ -2,7 +2,7 @@
 
 #![allow(incomplete_features)]
 #![feature(const_trait_impl)]
-#![feature(const_fn)]
+#![feature(const_fn_trait_bound)]
 
 use std::marker::PhantomData;
 
diff --git a/src/test/ui/rfc-2632-const-trait-impl/stability.stderr b/src/test/ui/rfc-2632-const-trait-impl/stability.stderr
index 54d7cfd5d79..5b2ebccef1c 100644
--- a/src/test/ui/rfc-2632-const-trait-impl/stability.stderr
+++ b/src/test/ui/rfc-2632-const-trait-impl/stability.stderr
@@ -1,4 +1,4 @@
-error[E0723]: trait methods cannot be stable const fn
+error: trait methods cannot be stable const fn
   --> $DIR/stability.rs:14:5
    |
 LL | /     fn sub(self, rhs: Self) -> Self {
@@ -17,4 +17,3 @@ LL |     Int(1i32) + Int(2i32)
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0723`.