Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

further split up const_fn feature flag #84310

Merged
merged 6 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ 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),
RalfJung marked this conversation as resolved.
Show resolved Hide resolved

/// Allows unsizing coercions in `const fn`.
(active, const_fn_unsize, "1.53.0", Some(64992), None),
RalfJung marked this conversation as resolved.
Show resolved Hide resolved

/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
(active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),

Expand Down
42 changes: 17 additions & 25 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
}
Expand Down Expand Up @@ -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",
)
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/const-eval/issue-49296.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/consts/const-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 28 additions & 28 deletions src/test/ui/consts/min_const_fn/min_const_fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
12 changes: 6 additions & 6 deletions src/test/ui/consts/min_const_fn/min_const_fn_dyn.stderr
Original file line number Diff line number Diff line change
@@ -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`.
8 changes: 4 additions & 4 deletions src/test/ui/consts/unsizing-cast-non-null.stderr
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion src/test/ui/consts/unstable-const-fn-in-libcore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// check-pass

#![feature(const_fn)]
#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]
#![allow(incomplete_features)]

struct S;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// check-pass

#![feature(const_fn)]
#![feature(const_trait_impl)]
#![feature(const_fn_trait_bound)]
#![allow(incomplete_features)]

struct S;
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rfc-2632-const-trait-impl/generic-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#![allow(incomplete_features)]
#![feature(const_trait_impl)]
#![feature(const_fn)]
#![feature(const_fn_trait_bound)]

use std::marker::PhantomData;

Expand Down