Skip to content

Commit

Permalink
forbid mutable references in all constants except const fns
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Jun 19, 2020
1 parent 72417d8 commit 2f9d338
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustc_mir/transform/check_consts/ops.rs
Expand Up @@ -205,6 +205,12 @@ impl NonConstOp for CellBorrow {
#[derive(Debug)]
pub struct MutBorrow;
impl NonConstOp for MutBorrow {
fn is_allowed_in_item(&self, ccx: &ConstCx<'_, '_>) -> bool {
// Forbid everywhere except in const fn
ccx.const_kind() == hir::ConstContext::ConstFn
&& ccx.tcx.features().enabled(Self::feature_gate().unwrap())
}

fn feature_gate() -> Option<Symbol> {
Some(sym::const_mut_refs)
}
Expand Down

0 comments on commit 2f9d338

Please sign in to comment.