Skip to content

Commit 5a3ddcd

Browse files
Update test with improved diagnostics
Now, `derived_from_illegal_borrow` is also applied to reborrows, so we don't show the user a useless error message.
1 parent 66e9f88 commit 5a3ddcd

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/test/ui/consts/const-multi-ref.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
// Ensure that we point the user to the erroneous borrow but not to any subsequent borrows of that
2+
// initial one.
3+
14
const _X: i32 = {
25
let mut a = 5;
3-
let p = &mut a; //~ ERROR references in constants may only refer to immutable values
6+
let p = &mut a; //~ ERROR references in constants may only refer to immutable values
47

5-
let reborrow = {p}; //~ ERROR references in constants may only refer to immutable values
8+
let reborrow = {p};
69
let pp = &reborrow;
710
let ppp = &pp;
811
***ppp
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
error[E0017]: references in constants may only refer to immutable values
2-
--> $DIR/const-multi-ref.rs:3:13
2+
--> $DIR/const-multi-ref.rs:6:13
33
|
44
LL | let p = &mut a;
55
| ^^^^^^ constants require immutable values
66

7-
error[E0017]: references in constants may only refer to immutable values
8-
--> $DIR/const-multi-ref.rs:5:21
9-
|
10-
LL | let reborrow = {p};
11-
| ^ constants require immutable values
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

159
For more information about this error, try `rustc --explain E0017`.

0 commit comments

Comments
 (0)