1
Fork 0

forbid mutable references in all constants except const fns

This commit is contained in:
Christian Poveda 2020-06-06 19:25:02 -05:00
parent 72417d84fb
commit 2f9d33830c
No known key found for this signature in database
GPG key ID: 27525EF5E7420A50

View file

@ -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)
}