]> git.lizzy.rs Git - rust.git/commitdiff
Add `#![feature(const_fn_impl)]`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Fri, 2 Oct 2020 19:02:41 +0000 (12:02 -0700)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Tue, 6 Oct 2020 02:56:50 +0000 (19:56 -0700)
compiler/rustc_feature/src/active.rs
compiler/rustc_mir/src/transform/check_consts/ops.rs
compiler/rustc_span/src/symbol.rs

index cd018ae1204f9a2c527cf5064fb9014c9edd7ff5..19da310b3b20a1667ef3814721df8ed21fa45a11 100644 (file)
@@ -596,6 +596,9 @@ pub fn set(&self, features: &mut Features, span: Span) {
     /// Allows rustc to inject a default alloc_error_handler
     (active, default_alloc_error_handler, "1.48.0", Some(66741), None),
 
+    /// Allows argument and return position `impl Trait` in a `const fn`.
+    (active, const_fn_impl_trait, "1.48.0", Some(77463), None),
+
     // -------------------------------------------------------------------------
     // feature-group-end: actual feature gates
     // -------------------------------------------------------------------------
index 9a1b77e994d1350d66b89fe561d28d5a1ab13ac0..91008f00930dbceac89c5d360ed56e8a5cfba7d3 100644 (file)
@@ -559,11 +559,20 @@ fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<
     pub struct ImplTrait;
     impl NonConstOp for ImplTrait {
         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_impl_trait)
+            }
         }
 
         fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
-            mcf_build_error(ccx, span, "`impl Trait` in const fn is unstable")
+            feature_err(
+                &ccx.tcx.sess.parse_sess,
+                sym::const_fn_impl_trait,
+                span,
+                &format!("`impl Trait` is not allowed in {}s", ccx.const_kind()),
+            )
         }
     }
 
index 6309b00f5f514897570583e3e04752264c73cf34..123f1f76765f7a4c61a2426d71057c1f45cd8f10 100644 (file)
         const_fn,
         const_fn_floating_point_arithmetic,
         const_fn_fn_ptr_basics,
+        const_fn_impl_trait,
         const_fn_transmute,
         const_fn_union,
         const_generics,