diff options
| author | Christian Poveda <christianpoveda@protonmail.com> | 2019-11-22 19:59:34 -0500 |
|---|---|---|
| committer | Christian Poveda <christianpoveda@protonmail.com> | 2019-12-02 09:03:41 -0500 |
| commit | d92e9b7374bb2087e0eb4803bfabb030c1397bcd (patch) | |
| tree | a0f16860a776e5272455c29cad7aa73bfaa39ee9 | |
| parent | de60f721c4983b1d43a305f0603a7ba6207b888d (diff) | |
| download | rust-d92e9b7374bb2087e0eb4803bfabb030c1397bcd.tar.gz rust-d92e9b7374bb2087e0eb4803bfabb030c1397bcd.zip | |
Allow mutable derefs with feature gate
| -rw-r--r-- | src/librustc_mir/transform/check_consts/ops.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/consts/const-mut-refs/const_mut_refs.rs | 4 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/check_consts/ops.rs b/src/librustc_mir/transform/check_consts/ops.rs index 117d628af25..be5845eaa36 100644 --- a/src/librustc_mir/transform/check_consts/ops.rs +++ b/src/librustc_mir/transform/check_consts/ops.rs @@ -216,7 +216,11 @@ impl NonConstOp for MutBorrow { #[derive(Debug)] pub struct MutDeref; -impl NonConstOp for MutDeref {} +impl NonConstOp for MutDeref { + fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> { + Some(tcx.features().const_mut_refs) + } +} #[derive(Debug)] pub struct Panic; diff --git a/src/test/ui/consts/const-mut-refs/const_mut_refs.rs b/src/test/ui/consts/const-mut-refs/const_mut_refs.rs index 60a69cb9f3f..36174b2843d 100644 --- a/src/test/ui/consts/const-mut-refs/const_mut_refs.rs +++ b/src/test/ui/consts/const-mut-refs/const_mut_refs.rs @@ -7,7 +7,9 @@ struct Foo { } const fn bar(foo: &mut Foo) -> usize { - foo.x + 1 + let x = &mut foo.x; + *x = 1; + *x } fn main() { |
