about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2021-07-18 03:34:50 +0200
committerJonas Schievink <jonasschievink@gmail.com>2021-07-29 23:21:54 +0200
commitdbd126901ac7d6ee886e0a234e630b1fbfec9afd (patch)
treee5b1eae2ecbc3a582207071f2c59f63f8152a4ec /compiler
parenta985d8e6c7f0519fa1e147854430a381ac4eadf8 (diff)
Add feature gates for `for` and `?` in consts
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_feature/src/active.rs6
-rw-r--r--compiler/rustc_passes/src/check_const.rs9
-rw-r--r--compiler/rustc_span/src/symbol.rs2
3 files changed, 13 insertions, 4 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index bf99d298817..9faed49c88b 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -677,6 +677,12 @@ declare_features! (
     /// Allows `#[derive(Default)]` and `#[default]` on enums.
     (active, derive_default_enum, "1.56.0", Some(86985), None),
 
+    /// Allows `for _ in _` loops in const contexts.
+    (active, const_for, "1.55.0", None, None),
+
+    /// Allows the `?` operator in const contexts.
+    (active, const_try, "1.55.0", None, None),
+
     // -------------------------------------------------------------------------
     // feature-group-end: actual feature gates
     // -------------------------------------------------------------------------
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs
index 6ee54cfe37f..f6a93f5e02d 100644
--- a/compiler/rustc_passes/src/check_const.rs
+++ b/compiler/rustc_passes/src/check_const.rs
@@ -40,13 +40,14 @@ impl NonConstExpr {
         use hir::MatchSource::*;
 
         let gates: &[_] = match self {
-            // A `for` loop's desugaring contains a call to `IntoIterator::into_iter`,
-            // so they are not yet allowed.
-            // Likewise, `?` desugars to a call to `Try::into_result`.
-            Self::Loop(ForLoop) | Self::Match(ForLoopDesugar | TryDesugar | AwaitDesugar) => {
+            Self::Match(AwaitDesugar) => {
                 return None;
             }
 
+            Self::Loop(ForLoop) | Self::Match(ForLoopDesugar) => &[sym::const_for],
+
+            Self::Match(TryDesugar) => &[sym::const_try],
+
             Self::Match(IfLetGuardDesugar) => bug!("`if let` guard outside a `match` expression"),
 
             // All other expressions are allowed.
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 114750d9b7b..295e53aba35 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -410,6 +410,7 @@ symbols! {
         const_fn_transmute,
         const_fn_union,
         const_fn_unsize,
+        const_for,
         const_format_args,
         const_generic_defaults,
         const_generics,
@@ -432,6 +433,7 @@ symbols! {
         const_trait_bound_opt_out,
         const_trait_impl,
         const_transmute,
+        const_try,
         constant,
         constructor,
         contents,