+/// An expression that is not *always* legal in a const context.
+#[derive(Clone, Copy)]
+enum NonConstExpr {
+ Loop(hir::LoopSource),
+ Match(hir::MatchSource),
+}
+
+impl NonConstExpr {
+ fn name(self) -> &'static str {
+ match self {
+ Self::Loop(src) => src.name(),
+ Self::Match(src) => src.name(),
+ }
+ }
+
+ /// Returns `true` if all feature gates required to enable this expression are turned on, or
+ /// `None` if there is no feature gate corresponding to this expression.
+ fn is_feature_gate_enabled(self, features: &Features) -> Option<bool> {
+ use hir::MatchSource::*;
+ match self {
+ | Self::Match(Normal)
+ | Self::Match(IfDesugar { .. })
+ | Self::Match(IfLetDesugar { .. })
+ => Some(features.const_if_match),
+
+ _ => None,
+ }
+ }
+}
+