From fdad6ab3a3e3f2cdd6bda7f2cc0c7da698ac01a0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Apr 2021 18:36:41 +0200 Subject: [PATCH 1/6] move 'trait bounds on const fn' to separate feature gate --- compiler/rustc_feature/src/active.rs | 3 ++ .../src/transform/check_consts/ops.rs | 11 ++++-- compiler/rustc_span/src/symbol.rs | 1 + library/alloc/src/lib.rs | 1 + library/core/src/lib.rs | 1 + src/test/ui/consts/const-eval/issue-49296.rs | 2 +- src/test/ui/consts/const-fn.rs | 3 +- .../consts/min_const_fn/min_const_fn.stderr | 36 +++++++++---------- .../min_const_fn/min_const_fn_dyn.stderr | 7 ++-- .../ui/consts/unstable-const-fn-in-libcore.rs | 2 +- .../call-generic-method-chain.rs | 2 +- .../call-generic-method-dup-bound.rs | 2 +- .../call-generic-method-pass.rs | 2 +- .../generic-bound.rs | 2 +- 14 files changed, 44 insertions(+), 31 deletions(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 6fd1af60fe2d8..d04c89aa13c23 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -576,6 +576,9 @@ declare_features! ( /// Allows using and casting function pointers in a `const fn`. (active, const_fn_fn_ptr_basics, "1.48.0", Some(57563), None), + /// Allows trait bounds in `const fn`. + (active, const_fn_trait_bound, "1.53.0", Some(57563), None), + /// Allows to use the `#[cmse_nonsecure_entry]` attribute. (active, cmse_nonsecure_entry, "1.48.0", Some(75835), None), diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index a18c1f7452404..c215ae11cf8d8 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -642,12 +642,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", ) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 52270f0e6277b..6acf77a8e6ed8 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -382,6 +382,7 @@ symbols! { const_fn, const_fn_floating_point_arithmetic, const_fn_fn_ptr_basics, + const_fn_trait_bound, const_fn_transmute, const_fn_union, const_generic_defaults, diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 14cb1d3b405c2..70ff78d564e0b 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -90,6 +90,7 @@ #![feature(coerce_unsized)] #![feature(const_btree_new)] #![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 d0c52a4459190..495edc70f38de 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -86,6 +86,7 @@ #![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/test/ui/consts/const-eval/issue-49296.rs b/src/test/ui/consts/const-eval/issue-49296.rs index 9fd9e8f36472d..f2d9758b8dc08 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: T) -> U { #[repr(C)] diff --git a/src/test/ui/consts/const-fn.rs b/src/test/ui/consts/const-fn.rs index 7b924aa46aa3c..1928c51885eff 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/min_const_fn/min_const_fn.stderr b/src/test/ui/consts/min_const_fn/min_const_fn.stderr index ee5434b147b66..b629955eb2bfe 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 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: T) -> T { t } | ^ | = note: see issue #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: T) -> T { t } | ^ | = note: see issue #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 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 Foo { | ^ | = note: see issue #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 Foo { | ^ | = note: see issue #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 Foo { | ^ | = note: see issue #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) {} | ^^^^^^^^^^^^^^^^^^^^ | = note: see issue #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) {} | | | 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 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,23 +270,23 @@ 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 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 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 --> $DIR/min_const_fn.rs:134:63 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 1394db591cadd..11bb82639a340 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,11 +1,11 @@ -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 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 --> $DIR/min_const_fn_dyn.rs:12:66 @@ -18,4 +18,5 @@ LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) } error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0723`. +Some errors have detailed explanations: E0658, E0723. +For more information about an 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 43951c6854b1a..2fbbbbffac484 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 { 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 6a511f4ed3ed8..c37990b1af3dd 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 b39d27779f45f..d553b2ab8ec47 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 e968e6ec7bb80..74b0d5fbe474b 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 7829ffe2a38d9..d368082031260 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; From fbfaab2cb745e98ab0f01631803319fd4cce2709 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Apr 2021 19:02:33 +0200 Subject: [PATCH 2/6] separate feature flag for unsizing casts in const fn --- compiler/rustc_feature/src/active.rs | 3 ++ .../src/transform/check_consts/ops.rs | 31 ++++++------------- compiler/rustc_span/src/symbol.rs | 1 + library/alloc/src/lib.rs | 2 +- library/core/src/lib.rs | 2 +- .../consts/min_const_fn/min_const_fn.stderr | 20 ++++++------ .../min_const_fn/min_const_fn_dyn.stderr | 9 +++--- .../ui/consts/unsizing-cast-non-null.stderr | 8 ++--- 8 files changed, 33 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index d04c89aa13c23..590d16e9a5de7 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -579,6 +579,9 @@ declare_features! ( /// 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), + /// Allows to use the `#[cmse_nonsecure_entry]` attribute. (active, cmse_nonsecure_entry, "1.48.0", Some(75835), None), diff --git a/compiler/rustc_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index c215ae11cf8d8..0aa342f0efb8a 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -540,14 +540,19 @@ 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", + "unsizing casts to types besides slices are not allowed in const fn" ) } } @@ -677,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 \ - for more information", - ); - err.help("add `#![feature(const_fn)]` to the crate attributes to enable"); - err -} diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 6acf77a8e6ed8..6456e96fa6a11 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -385,6 +385,7 @@ symbols! { const_fn_trait_bound, const_fn_transmute, const_fn_union, + const_fn_unsize, const_generic_defaults, const_generics, const_generics_defaults, diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 70ff78d564e0b..3a5dcec668ff6 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -89,7 +89,7 @@ #![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)] diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 495edc70f38de..af06ea00f19b5 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -81,7 +81,7 @@ #![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)] 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 b629955eb2bfe..e6ce7e12520f5 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 @@ -288,32 +288,32 @@ LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() } = note: see issue #57563 for more information = 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 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable + = note: see issue #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 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable + = note: see issue #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 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable + = note: see issue #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 11bb82639a340..cf635d656996e 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 @@ -7,16 +7,15 @@ LL | x.0.field; = note: see issue #57563 for more information = 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 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable + = note: see issue #64992 for more information + = help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable error: aborting due to 2 previous errors -Some errors have detailed explanations: E0658, E0723. -For more information about an error, try `rustc --explain E0658`. +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 dc08ccd02b646..79691cddfb403 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 for more information - = help: add `#![feature(const_fn)]` to the crate attributes to enable + = note: see issue #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`. From bd9556956ade485ae540fa6b25d2d2b1b2e8b958 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Apr 2021 22:05:45 +0200 Subject: [PATCH 3/6] fix feature use in rustc libs --- compiler/rustc_ast/src/lib.rs | 3 ++- compiler/rustc_hir/src/lib.rs | 1 - compiler/rustc_index/src/lib.rs | 1 - compiler/rustc_infer/src/lib.rs | 1 - compiler/rustc_middle/src/lib.rs | 1 - compiler/rustc_mir/src/lib.rs | 1 - compiler/rustc_mir_build/src/lib.rs | 1 - compiler/rustc_passes/src/lib.rs | 1 - compiler/rustc_query_system/src/lib.rs | 1 - compiler/rustc_span/src/lib.rs | 1 - compiler/rustc_target/src/lib.rs | 1 - 11 files changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 1e6da044ec039..ffec28a395fdb 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_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 36a30900fb26c..65c99535c4e34 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 3ced3920cfdfe..9c306d0251200 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 25a262d7e482b..15b4a7ed20717 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 1db03e9165b88..45ea07a3db6b6 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 b0db4f9e649b3..783aa9465c395 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_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 23bc1da09b555..da9a0b08e865b 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 933e8ad1d727c..0be7ef7e12a3e 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 071144f38e702..be72baefb9edc 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 6f6ff37c525a2..d30236ec3eccc 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_target/src/lib.rs b/compiler/rustc_target/src/lib.rs index b54764b9e3239..6702538874705 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)] From 04db4abbfceb39374ff21ccce563791c3112a153 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 19 Apr 2021 10:15:56 +0200 Subject: [PATCH 4/6] add gate tests and pacify tidy --- compiler/rustc_feature/src/active.rs | 12 ++++---- .../src/transform/check_consts/ops.rs | 2 +- .../consts/const_fn_trait_bound.gated.stderr | 8 +++++ src/test/ui/consts/const_fn_trait_bound.rs | 17 +++++++++++ .../consts/const_fn_trait_bound.stock.stderr | 30 +++++++++++++++++++ .../ui/consts/const_fn_unsize.gated.stderr | 8 +++++ src/test/ui/consts/const_fn_unsize.rs | 16 ++++++++++ .../ui/consts/const_fn_unsize.stock.stderr | 12 ++++++++ 8 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/consts/const_fn_trait_bound.gated.stderr create mode 100644 src/test/ui/consts/const_fn_trait_bound.rs create mode 100644 src/test/ui/consts/const_fn_trait_bound.stock.stderr create mode 100644 src/test/ui/consts/const_fn_unsize.gated.stderr create mode 100644 src/test/ui/consts/const_fn_unsize.rs create mode 100644 src/test/ui/consts/const_fn_unsize.stock.stderr diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 590d16e9a5de7..74e5a4e26e863 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -576,12 +576,6 @@ declare_features! ( /// Allows using and casting function pointers in a `const fn`. (active, const_fn_fn_ptr_basics, "1.48.0", Some(57563), 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), - /// Allows to use the `#[cmse_nonsecure_entry]` attribute. (active, cmse_nonsecure_entry, "1.48.0", Some(75835), None), @@ -651,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_mir/src/transform/check_consts/ops.rs b/compiler/rustc_mir/src/transform/check_consts/ops.rs index 0aa342f0efb8a..ffeaaf60a30cf 100644 --- a/compiler/rustc_mir/src/transform/check_consts/ops.rs +++ b/compiler/rustc_mir/src/transform/check_consts/ops.rs @@ -552,7 +552,7 @@ impl NonConstOp for UnsizingCast { &ccx.tcx.sess.parse_sess, sym::const_fn_unsize, span, - "unsizing casts to types besides slices are not allowed in const fn" + "unsizing casts to types besides slices are not allowed in const fn", ) } } 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 0000000000000..ded05cb17c513 --- /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 0000000000000..b1ef820d827b4 --- /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() {} +//[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 0000000000000..2ad45f3afde8f --- /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() {} + | ^ + | + = note: see issue #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 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 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 0000000000000..8a65c274ca933 --- /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 0000000000000..0cab3b0a031b1 --- /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 0000000000000..cc746d4f175ca --- /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 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`. From 46d09f7a4b2fe6675f06394a187cef46728412d3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 19 Apr 2021 14:17:07 +0200 Subject: [PATCH 5/6] remove E0723 error code --- compiler/rustc_error_codes/src/error_codes.rs | 2 +- .../src/error_codes/E0723.md | 20 ------------------- .../src/transform/check_consts/validation.rs | 14 ++++++------- .../stability.stderr | 3 +-- 4 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 compiler/rustc_error_codes/src/error_codes/E0723.md diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 4b529734328c7..41a1fa488d31b 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 bc2244219156c..0000000000000 --- 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) { // error! - // ... -} -``` - -To enable this feature on a nightly version of rustc, add the `const_fn` -feature flag: - -``` -#![feature(const_fn)] - -const fn foo(_: T) { // ok! - // ... -} -``` diff --git a/compiler/rustc_mir/src/transform/check_consts/validation.rs b/compiler/rustc_mir/src/transform/check_consts/validation.rs index ce5e41d3e7c86..cf7d404a07789 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/src/test/ui/rfc-2632-const-trait-impl/stability.stderr b/src/test/ui/rfc-2632-const-trait-impl/stability.stderr index 54d7cfd5d7973..5b2ebccef1c6d 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`. From 49054c3617bb04ba4f108ab7a5fbe6cda74bcbd3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 24 Apr 2021 23:17:06 +0200 Subject: [PATCH 6/6] update rustc-perf version that is used for PGO --- src/ci/pgo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/pgo.sh b/src/ci/pgo.sh index 95cf1183fc17a..ad2a8c771de9c 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