Skip to content

Commit 2f9d338

Browse files
committed
forbid mutable references in all constants except const fns
1 parent 72417d8 commit 2f9d338

File tree

1 file changed

+6
-0
lines changed
  • src/librustc_mir/transform/check_consts

1 file changed

+6
-0
lines changed

src/librustc_mir/transform/check_consts/ops.rs

+6
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ impl NonConstOp for CellBorrow {
205205
#[derive(Debug)]
206206
pub struct MutBorrow;
207207
impl NonConstOp for MutBorrow {
208+
fn is_allowed_in_item(&self, ccx: &ConstCx<'_, '_>) -> bool {
209+
// Forbid everywhere except in const fn
210+
ccx.const_kind() == hir::ConstContext::ConstFn
211+
&& ccx.tcx.features().enabled(Self::feature_gate().unwrap())
212+
}
213+
208214
fn feature_gate() -> Option<Symbol> {
209215
Some(sym::const_mut_refs)
210216
}

0 commit comments

Comments
 (0)