Skip to content

Commit e1d7681

Browse files
Add #![feature(const_fn_impl)]
1 parent a1dfd24 commit e1d7681

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Diff for: compiler/rustc_feature/src/active.rs

+3
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ declare_features! (
596596
/// Allows rustc to inject a default alloc_error_handler
597597
(active, default_alloc_error_handler, "1.48.0", Some(66741), None),
598598

599+
/// Allows argument and return position `impl Trait` in a `const fn`.
600+
(active, const_fn_impl_trait, "1.48.0", Some(77463), None),
601+
599602
// -------------------------------------------------------------------------
600603
// feature-group-end: actual feature gates
601604
// -------------------------------------------------------------------------

Diff for: compiler/rustc_mir/src/transform/check_consts/ops.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,20 @@ pub mod ty {
559559
pub struct ImplTrait;
560560
impl NonConstOp for ImplTrait {
561561
fn status_in_item(&self, ccx: &ConstCx<'_, '_>) -> Status {
562-
mcf_status_in_item(ccx)
562+
if ccx.const_kind() != hir::ConstContext::ConstFn {
563+
Status::Allowed
564+
} else {
565+
Status::Unstable(sym::const_fn_impl_trait)
566+
}
563567
}
564568

565569
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
566-
mcf_build_error(ccx, span, "`impl Trait` in const fn is unstable")
570+
feature_err(
571+
&ccx.tcx.sess.parse_sess,
572+
sym::const_fn_impl_trait,
573+
span,
574+
&format!("`impl Trait` is not allowed in {}s", ccx.const_kind()),
575+
)
567576
}
568577
}
569578

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ symbols! {
355355
const_fn,
356356
const_fn_floating_point_arithmetic,
357357
const_fn_fn_ptr_basics,
358+
const_fn_impl_trait,
358359
const_fn_transmute,
359360
const_fn_union,
360361
const_generics,

0 commit comments

Comments
 (0)