Skip to content

Commit 7ec3c10

Browse files
committed
Add tests for mutable borrows
1 parent 59c6c49 commit 7ec3c10

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/test/ui/consts/const_let_eq.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,4 @@ fn main() {
465465
test!(AND, bit_and_assign(W(0b1011_1111_1111_1111_1111)), 0b0011_1100_1101_0100);
466466
test!(OR, bit_or_assign(W(0b1011_0000_0000_0000)), 0b1111_0011_0101_1001);
467467
test!(XOR, bit_xor_assign(W(0b0000_0000_0000_0000)), 0b1100_0011_1001_0011);
468-
}
468+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const fn mutable_ref_in_const() -> u8 {
2+
let mut a = 0;
3+
let b = &mut a; //~ ERROR mutable references in const fn are unstable
4+
*b
5+
}
6+
7+
struct X;
8+
9+
impl X {
10+
const fn inherent_mutable_ref_in_const() -> u8 {
11+
let mut a = 0;
12+
let b = &mut a; //~ ERROR mutable references in const fn are unstable
13+
*b
14+
}
15+
}
16+
17+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: mutable references in const fn are unstable
2+
--> $DIR/mutable_borrow.rs:3:9
3+
|
4+
LL | let b = &mut a; //~ ERROR mutable references in const fn are unstable
5+
| ^
6+
7+
error: mutable references in const fn are unstable
8+
--> $DIR/mutable_borrow.rs:12:13
9+
|
10+
LL | let b = &mut a; //~ ERROR mutable references in const fn are unstable
11+
| ^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)