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()))
}
Operand::Move(place) | Operand::Copy(place) => {
check_place(tcx, place, span, def_id, body)
}
- Operand::Constant(_) => Ok(()),
+ Operand::Constant(c) => match c.check_static_ptr(tcx) {
+ Some(_) => Err((span, "cannot access `static` items in const fn".into())),
+ None => Ok(()),
+ },
}
}
while let &[ref proj_base @ .., elem] = cursor {
cursor = proj_base;
match elem {
- ProjectionElem::Downcast(..) => {
- return Err((span, "`match` or `if let` in `const fn` is unstable".into()));
- }
+ ProjectionElem::Downcast(..) if !tcx.features().const_if_match
+ => return Err((span, "`match` or `if let` in `const fn` is unstable".into())),
+ ProjectionElem::Downcast(_symbol, _variant_index) => {}
+
ProjectionElem::Field(..) => {
let base_ty = Place::ty_from(&place.base, &proj_base, body, tcx).ty;
if let Some(def) = base_ty.ty_adt_def() {
}
}
- match place.base {
- PlaceBase::Static(box Static { kind: StaticKind::Static, .. }) => {
- Err((span, "cannot access `static` items in const fn".into()))
- }
- PlaceBase::Local(_)
- | PlaceBase::Static(box Static { kind: StaticKind::Promoted(_, _), .. }) => Ok(()),
- }
+ Ok(())
}
/// Returns whether `allow_internal_unstable(..., <feature_gate>, ...)` is present.
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 { .. } => Ok(()),
+ TerminatorKind::SwitchInt { discr, switch_ty: _, values: _, targets: _ } => {
+ check_operand(tcx, discr, span, def_id, body)
+ }
+
| TerminatorKind::Abort | TerminatorKind::Unreachable => {
Err((span, "const fn with unreachable code is not stable".into()))
}