Skip to content

Commit d92e9b7

Browse files
committed
Allow mutable derefs with feature gate
1 parent de60f72 commit d92e9b7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/librustc_mir/transform/check_consts/ops.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ impl NonConstOp for MutBorrow {
216216

217217
#[derive(Debug)]
218218
pub struct MutDeref;
219-
impl NonConstOp for MutDeref {}
219+
impl NonConstOp for MutDeref {
220+
fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> {
221+
Some(tcx.features().const_mut_refs)
222+
}
223+
}
220224

221225
#[derive(Debug)]
222226
pub struct Panic;

src/test/ui/consts/const-mut-refs/const_mut_refs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ struct Foo {
77
}
88

99
const fn bar(foo: &mut Foo) -> usize {
10-
foo.x + 1
10+
let x = &mut foo.x;
11+
*x = 1;
12+
*x
1113
}
1214

1315
fn main() {

0 commit comments

Comments
 (0)