#[derive(Debug)]
pub struct IfOrMatch;
impl NonConstOp for IfOrMatch {
+ fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> {
+ Some(tcx.features().const_if_match)
+ }
+
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
// This should be caught by the HIR const-checker.
item.tcx.sess.delay_span_bug(
check_rvalue(tcx, body, def_id, rval, span)
}
- StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
+ | StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _)
+ if !tcx.features().const_if_match
+ => {
Err((span, "loops and conditional expressions are not stable in const fn".into()))
}
check_operand(tcx, value, span, def_id, body)
},
- TerminatorKind::FalseEdges { .. } | TerminatorKind::SwitchInt { .. } => Err((
+ | TerminatorKind::FalseEdges { .. }
+ | TerminatorKind::SwitchInt { .. }
+ if !tcx.features().const_if_match
+ => Err((
span,
"loops and conditional expressions are not stable in const fn".into(),
)),
+ | TerminatorKind::FalseEdges { .. }
+ | TerminatorKind::SwitchInt { .. }
+ => Ok(()),
+
| TerminatorKind::Abort | TerminatorKind::Unreachable => {
Err((span, "const fn with unreachable code is not stable".into()))
}
self.const_check_violated(source.name(), e.span);
}
- hir::ExprKind::Match(_, _, source) => {
+ hir::ExprKind::Match(_, _, source) if !self.tcx.features().const_if_match => {
use hir::MatchSource::*;
let op = match source {
/// Allows using the `#[register_attr]` attribute.
(active, register_tool, "1.41.0", Some(66079), None),
+ /// Allows the use of `if` and `match` in constants.
+ (active, const_if_match, "1.41.0", Some(49146), None),
+
// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
const_fn,
const_fn_union,
const_generics,
+ const_if_match,
const_indexing,
const_in_array_repeat_expressions,
const_let,