mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
separate feature flag for unsizing casts in const fn
This commit is contained in:
parent
fdad6ab3a3
commit
fbfaab2cb7
@ -579,6 +579,9 @@ declare_features! (
|
|||||||
/// Allows trait bounds in `const fn`.
|
/// Allows trait bounds in `const fn`.
|
||||||
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
|
(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.
|
/// Allows to use the `#[cmse_nonsecure_entry]` attribute.
|
||||||
(active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),
|
(active, cmse_nonsecure_entry, "1.48.0", Some(75835), None),
|
||||||
|
|
||||||
|
@ -540,14 +540,19 @@ impl NonConstOp for UnionAccess {
|
|||||||
pub struct UnsizingCast;
|
pub struct UnsizingCast;
|
||||||
impl NonConstOp for UnsizingCast {
|
impl NonConstOp for UnsizingCast {
|
||||||
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
|
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> {
|
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
|
||||||
mcf_build_error(
|
feature_err(
|
||||||
ccx,
|
&ccx.tcx.sess.parse_sess,
|
||||||
|
sym::const_fn_unsize,
|
||||||
span,
|
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 <https://github.com/rust-lang/rust/issues/57563> \
|
|
||||||
for more information",
|
|
||||||
);
|
|
||||||
err.help("add `#![feature(const_fn)]` to the crate attributes to enable");
|
|
||||||
err
|
|
||||||
}
|
|
||||||
|
@ -385,6 +385,7 @@ symbols! {
|
|||||||
const_fn_trait_bound,
|
const_fn_trait_bound,
|
||||||
const_fn_transmute,
|
const_fn_transmute,
|
||||||
const_fn_union,
|
const_fn_union,
|
||||||
|
const_fn_unsize,
|
||||||
const_generic_defaults,
|
const_generic_defaults,
|
||||||
const_generics,
|
const_generics,
|
||||||
const_generics_defaults,
|
const_generics_defaults,
|
||||||
|
@ -89,7 +89,7 @@
|
|||||||
#![feature(cfg_target_has_atomic)]
|
#![feature(cfg_target_has_atomic)]
|
||||||
#![feature(coerce_unsized)]
|
#![feature(coerce_unsized)]
|
||||||
#![feature(const_btree_new)]
|
#![feature(const_btree_new)]
|
||||||
#![feature(const_fn)]
|
#![cfg_attr(bootstrap, feature(const_fn))]
|
||||||
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
|
#![cfg_attr(not(bootstrap), feature(const_fn_trait_bound))]
|
||||||
#![feature(cow_is_borrowed)]
|
#![feature(cow_is_borrowed)]
|
||||||
#![feature(const_cow_is_borrowed)]
|
#![feature(const_cow_is_borrowed)]
|
||||||
|
@ -81,7 +81,7 @@
|
|||||||
#![feature(const_refs_to_cell)]
|
#![feature(const_refs_to_cell)]
|
||||||
#![feature(const_panic)]
|
#![feature(const_panic)]
|
||||||
#![feature(const_pin)]
|
#![feature(const_pin)]
|
||||||
#![feature(const_fn)]
|
#![cfg_attr(bootstrap, feature(const_fn))]
|
||||||
#![feature(const_fn_union)]
|
#![feature(const_fn_union)]
|
||||||
#![feature(const_impl_trait)]
|
#![feature(const_impl_trait)]
|
||||||
#![feature(const_fn_floating_point_arithmetic)]
|
#![feature(const_fn_floating_point_arithmetic)]
|
||||||
|
@ -288,32 +288,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
|
= 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
|
= 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
|
--> $DIR/min_const_fn.rs:134:63
|
||||||
|
|
|
|
||||||
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
|
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
|
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= 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
|
--> $DIR/min_const_fn.rs:134:63
|
||||||
|
|
|
|
||||||
LL | const fn no_dyn_trait_ret() -> &'static dyn std::fmt::Debug { &() }
|
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
|
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= 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
|
--> $DIR/min_const_fn.rs:141:42
|
||||||
|
|
|
|
||||||
LL | const fn really_no_traits_i_mean_it() { (&() as &dyn std::fmt::Debug, ()).1 }
|
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
|
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: function pointers cannot appear in constant functions
|
error[E0658]: function pointers cannot appear in constant functions
|
||||||
--> $DIR/min_const_fn.rs:144:21
|
--> $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
|
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`.
|
For more information about an error, try `rustc --explain E0013`.
|
||||||
|
@ -7,16 +7,15 @@ LL | x.0.field;
|
|||||||
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
|
= 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
|
= 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
|
--> $DIR/min_const_fn_dyn.rs:12:66
|
||||||
|
|
|
|
||||||
LL | const fn no_inner_dyn_trait_ret() -> Hide { Hide(HasDyn { field: &0 }) }
|
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
|
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0658, E0723.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
For more information about an error, try `rustc --explain E0658`.
|
|
||||||
|
@ -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
|
--> $DIR/unsizing-cast-non-null.rs:6:5
|
||||||
|
|
|
|
||||||
LL | NonNull::<[T; 0]>::dangling()
|
LL | NonNull::<[T; 0]>::dangling()
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
|
= note: see issue #64992 <https://github.com/rust-lang/rust/issues/64992> for more information
|
||||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
= help: add `#![feature(const_fn_unsize)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to previous error
|
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`.
|
||||||
|
Loading…
Reference in New Issue
Block a user