separate feature flag for unsizing casts in const fn
This commit is contained in:
parent
fdad6ab3a3
commit
fbfaab2cb7
8 changed files with 33 additions and 43 deletions
|
|
@ -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),
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <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_transmute,
|
||||
const_fn_union,
|
||||
const_fn_unsize,
|
||||
const_generic_defaults,
|
||||
const_generics,
|
||||
const_generics_defaults,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue