Add tests for mutable borrows

This commit is contained in:
Oliver Scherer 2018-11-23 15:30:10 +01:00
parent 59c6c4942a
commit 7ec3c10d7e
3 changed files with 32 additions and 1 deletions

View file

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

View file

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

View file

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