From 7ec3c10d7e1bfac9e93b0138d2a9703d1f722dff Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 23 Nov 2018 15:30:10 +0100 Subject: [PATCH] Add tests for mutable borrows --- src/test/ui/consts/const_let_eq.rs | 2 +- .../ui/consts/min_const_fn/mutable_borrow.rs | 17 +++++++++++++++++ .../consts/min_const_fn/mutable_borrow.stderr | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/consts/min_const_fn/mutable_borrow.rs create mode 100644 src/test/ui/consts/min_const_fn/mutable_borrow.stderr diff --git a/src/test/ui/consts/const_let_eq.rs b/src/test/ui/consts/const_let_eq.rs index 434aeaac5fd5..a2364c392f26 100644 --- a/src/test/ui/consts/const_let_eq.rs +++ b/src/test/ui/consts/const_let_eq.rs @@ -465,4 +465,4 @@ fn main() { test!(AND, bit_and_assign(W(0b1011_1111_1111_1111_1111)), 0b0011_1100_1101_0100); test!(OR, bit_or_assign(W(0b1011_0000_0000_0000)), 0b1111_0011_0101_1001); test!(XOR, bit_xor_assign(W(0b0000_0000_0000_0000)), 0b1100_0011_1001_0011); -} \ No newline at end of file +} diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.rs b/src/test/ui/consts/min_const_fn/mutable_borrow.rs new file mode 100644 index 000000000000..85f9a154c849 --- /dev/null +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.rs @@ -0,0 +1,17 @@ +const fn mutable_ref_in_const() -> u8 { + let mut a = 0; + let b = &mut a; //~ ERROR mutable references in const fn are unstable + *b +} + +struct X; + +impl X { + const fn inherent_mutable_ref_in_const() -> u8 { + let mut a = 0; + let b = &mut a; //~ ERROR mutable references in const fn are unstable + *b + } +} + +fn main() {} diff --git a/src/test/ui/consts/min_const_fn/mutable_borrow.stderr b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr new file mode 100644 index 000000000000..7414fa94bfbc --- /dev/null +++ b/src/test/ui/consts/min_const_fn/mutable_borrow.stderr @@ -0,0 +1,14 @@ +error: mutable references in const fn are unstable + --> $DIR/mutable_borrow.rs:3:9 + | +LL | let b = &mut a; //~ ERROR mutable references in const fn are unstable + | ^ + +error: mutable references in const fn are unstable + --> $DIR/mutable_borrow.rs:12:13 + | +LL | let b = &mut a; //~ ERROR mutable references in const fn are unstable + | ^ + +error: aborting due to 2 previous errors +