Add feature gates for for and ? in consts

This commit is contained in:
Jonas Schievink 2021-07-18 03:34:50 +02:00
parent a985d8e6c7
commit dbd126901a
8 changed files with 91 additions and 4 deletions

View file

@ -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.