- // Returning `true` for `Rvalue::Ref` indicates the borrow isn't
- // allowed in constants (and the `Checker` will error), and/or it
- // won't be promoted, due to `&mut ...` or interior mutability.
- Rvalue::Ref(_, kind, ref place) => {
- let ty = place.ty(cx.body, cx.tcx).ty;
-
- if let BorrowKind::Mut { .. } = kind {
- // In theory, any zero-sized value could be borrowed
- // mutably without consequences.
- match ty.kind {
- // Inside a `static mut`, &mut [...] is also allowed.
- | ty::Array(..)
- | ty::Slice(_)
- if cx.const_kind == Some(ConstKind::StaticMut)
- => {},
-
- // FIXME(eddyb): We only return false for `&mut []` outside a const
- // context which seems unnecessary given that this is merely a ZST.
- | ty::Array(_, len)
- if len.try_eval_usize(cx.tcx, cx.param_env) == Some(0)
- && cx.const_kind == None
- => {},
-
- _ => return true,
- }
- }
- }
-