Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b56b175

Browse files
committed
Auto merge of rust-lang#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?
2 parents 42816d6 + 49054c3 commit b56b175

File tree

37 files changed

+176
-114
lines changed

37 files changed

+176
-114
lines changed

compiler/rustc_ast/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
)]
1111
#![feature(box_syntax)]
1212
#![feature(box_patterns)]
13-
#![feature(const_fn)] // For the `transmute` in `P::new`
13+
#![cfg_attr(bootstrap, feature(const_fn))] // For the `transmute` in `P::new`
14+
#![cfg_attr(not(bootstrap), feature(const_fn_unsize))] // For the `transmute` in `P::new`
1415
#![feature(const_fn_transmute)]
1516
#![feature(const_panic)]
1617
#![feature(crate_visibility_modifier)]

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,6 @@ E0716: include_str!("./error_codes/E0716.md"),
416416
E0718: include_str!("./error_codes/E0718.md"),
417417
E0719: include_str!("./error_codes/E0719.md"),
418418
E0720: include_str!("./error_codes/E0720.md"),
419-
E0723: include_str!("./error_codes/E0723.md"),
420419
E0724: include_str!("./error_codes/E0724.md"),
421420
E0725: include_str!("./error_codes/E0725.md"),
422421
E0727: include_str!("./error_codes/E0727.md"),
@@ -636,6 +635,7 @@ E0781: include_str!("./error_codes/E0781.md"),
636635
E0717, // rustc_promotable without stability attribute
637636
// E0721, // `await` keyword
638637
E0722, // Malformed `#[optimize]` attribute
638+
// E0723, unstable feature in `const` context
639639
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
640640
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
641641
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`

compiler/rustc_error_codes/src/error_codes/E0723.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

compiler/rustc_feature/src/active.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,12 @@ declare_features! (
645645
/// Allows `extern "wasm" fn`
646646
(active, wasm_abi, "1.53.0", Some(83788), None),
647647

648+
/// Allows trait bounds in `const fn`.
649+
(active, const_fn_trait_bound, "1.53.0", Some(57563), None),
650+
651+
/// Allows unsizing coercions in `const fn`.
652+
(active, const_fn_unsize, "1.53.0", Some(64992), None),
653+
648654
// -------------------------------------------------------------------------
649655
// feature-group-end: actual feature gates
650656
// -------------------------------------------------------------------------

compiler/rustc_hir/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/hir.html
44
55
#![feature(crate_visibility_modifier)]
6-
#![feature(const_fn)] // For the unsizing cast on `&[]`
76
#![feature(const_panic)]
87
#![feature(extended_key_value_attributes)]
98
#![feature(in_band_lifetimes)]

compiler/rustc_index/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(allow_internal_unstable)]
2-
#![feature(const_fn)]
32
#![feature(const_panic)]
43
#![feature(extend_one)]
54
#![feature(iter_zip)]

compiler/rustc_infer/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#![feature(bool_to_option)]
1717
#![feature(box_patterns)]
1818
#![feature(box_syntax)]
19-
#![feature(const_fn)]
2019
#![feature(const_panic)]
2120
#![feature(extend_one)]
2221
#![feature(iter_zip)]

compiler/rustc_middle/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#![feature(bool_to_option)]
3030
#![feature(box_patterns)]
3131
#![feature(box_syntax)]
32-
#![feature(const_fn)]
3332
#![feature(const_panic)]
3433
#![feature(core_intrinsics)]
3534
#![feature(discriminant_kind)]

compiler/rustc_mir/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Rust MIR: a lowered representation of Rust.
1212
#![feature(bool_to_option)]
1313
#![feature(box_patterns)]
1414
#![feature(box_syntax)]
15-
#![feature(const_fn)]
1615
#![feature(const_panic)]
1716
#![feature(crate_visibility_modifier)]
1817
#![feature(decl_macro)]

compiler/rustc_mir/src/transform/check_consts/ops.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,17 @@ impl NonConstOp for UnionAccess {
540540
pub struct UnsizingCast;
541541
impl NonConstOp for UnsizingCast {
542542
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
543-
mcf_status_in_item(ccx)
543+
if ccx.const_kind() != hir::ConstContext::ConstFn {
544+
Status::Allowed
545+
} else {
546+
Status::Unstable(sym::const_fn_unsize)
547+
}
544548
}
545549

546550
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
547-
mcf_build_error(
548-
ccx,
551+
feature_err(
552+
&ccx.tcx.sess.parse_sess,
553+
sym::const_fn_unsize,
549554
span,
550555
"unsizing casts to types besides slices are not allowed in const fn",
551556
)
@@ -642,12 +647,17 @@ pub mod ty {
642647
}
643648

644649
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
645-
mcf_status_in_item(ccx)
650+
if ccx.const_kind() != hir::ConstContext::ConstFn {
651+
Status::Allowed
652+
} else {
653+
Status::Unstable(sym::const_fn_trait_bound)
654+
}
646655
}
647656

648657
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
649-
mcf_build_error(
650-
ccx,
658+
feature_err(
659+
&ccx.tcx.sess.parse_sess,
660+
sym::const_fn_trait_bound,
651661
span,
652662
"trait bounds other than `Sized` on const fn parameters are unstable",
653663
)
@@ -672,21 +682,3 @@ pub mod ty {
672682
}
673683
}
674684
}
675-
676-
fn mcf_status_in_item(ccx: &ConstCx<'_, '_>) -> Status {
677-
if ccx.const_kind() != hir::ConstContext::ConstFn {
678-
Status::Allowed
679-
} else {
680-
Status::Unstable(sym::const_fn)
681-
}
682-
}
683-
684-
fn mcf_build_error(ccx: &ConstCx<'_, 'tcx>, span: Span, msg: &str) -> DiagnosticBuilder<'tcx> {
685-
let mut err = struct_span_err!(ccx.tcx.sess, span, E0723, "{}", msg);
686-
err.note(
687-
"see issue #57563 <https://github.com/rust-lang/rust/issues/57563> \
688-
for more information",
689-
);
690-
err.help("add `#![feature(const_fn)]` to the crate attributes to enable");
691-
err
692-
}

0 commit comments

Comments
 (0)