summary refs log tree commit diff
path: root/compiler/rustc_passes/src/check_const.rs
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/rustc_passes/src/check_const.rs
parenta985d8e6c7f0519fa1e147854430a381ac4eadf8 (diff)
downloadrust-dbd126901ac7d6ee886e0a234e630b1fbfec9afd.tar.gz
rust-dbd126901ac7d6ee886e0a234e630b1fbfec9afd.zip
Add feature gates for `for` and `?` in consts
Diffstat (limited to 'compiler/rustc_passes/src/check_const.rs')
-rw-r--r--compiler/rustc_passes/src/check_const.rs9
1 files changed, 5 insertions, 4 deletions
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.