Skip to content

Commit 9ab3603

Browse files
committed
--bless bindings-after-at tests
1 parent 10ac7ea commit 9ab3603

File tree

7 files changed

+498
-67
lines changed

7 files changed

+498
-67
lines changed

src/librustc_mir/hair/pattern/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat) {
695695
};
696696
let msg = &format!(
697697
"cannot borrow `{}` as {} because it is also borrowed as {}",
698-
name, primary, also,
698+
name, also, primary,
699699
);
700700
let mut err = sess.struct_span_err(pat.span, msg);
701701
err.span_label(binding_span, &format!("{} borrow occurs here", primary));

src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ fn main() {
2929
drop(a);
3030
drop(b);
3131

32-
let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
33-
let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
32+
let ref a @ box ref mut b = Box::new(NC);
33+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
34+
let ref a @ box ref mut b = Box::new(NC);
35+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
3436
*b = NC;
3537
let ref a @ box ref mut b = Box::new(NC);
36-
//~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
38+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
39+
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
3740
*b = NC;
3841
drop(a);
3942

4043
let ref mut a @ box ref b = Box::new(NC);
41-
//~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
44+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
45+
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
4246
*a = Box::new(NC);
4347
drop(b);
4448
}

src/test/ui/pattern/bindings-after-at/borrowck-pat-at-and-box.stderr

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,42 @@ LL | let ref a @ box b = Box::new(NC);
2727
| | by-move pattern here
2828
| by-ref pattern here
2929

30+
error: cannot borrow `a` as mutable because it is also borrowed as immutable
31+
--> $DIR/borrowck-pat-at-and-box.rs:32:9
32+
|
33+
LL | let ref a @ box ref mut b = Box::new(NC);
34+
| -----^^^^^^^---------
35+
| | |
36+
| | mutable borrow occurs here
37+
| immutable borrow occurs here
38+
39+
error: cannot borrow `a` as mutable because it is also borrowed as immutable
40+
--> $DIR/borrowck-pat-at-and-box.rs:34:9
41+
|
42+
LL | let ref a @ box ref mut b = Box::new(NC);
43+
| -----^^^^^^^---------
44+
| | |
45+
| | mutable borrow occurs here
46+
| immutable borrow occurs here
47+
48+
error: cannot borrow `a` as mutable because it is also borrowed as immutable
49+
--> $DIR/borrowck-pat-at-and-box.rs:37:9
50+
|
51+
LL | let ref a @ box ref mut b = Box::new(NC);
52+
| -----^^^^^^^---------
53+
| | |
54+
| | mutable borrow occurs here
55+
| immutable borrow occurs here
56+
57+
error: cannot borrow `a` as immutable because it is also borrowed as mutable
58+
--> $DIR/borrowck-pat-at-and-box.rs:43:9
59+
|
60+
LL | let ref mut a @ box ref b = Box::new(NC);
61+
| ---------^^^^^^^-----
62+
| | |
63+
| | immutable borrow occurs here
64+
| mutable borrow occurs here
65+
3066
error[E0382]: use of moved value
3167
--> $DIR/borrowck-pat-at-and-box.rs:11:18
3268
|
@@ -46,7 +82,7 @@ LL | let a @ box b = Box::new(C);
4682
| value moved here
4783

4884
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
49-
--> $DIR/borrowck-pat-at-and-box.rs:35:21
85+
--> $DIR/borrowck-pat-at-and-box.rs:37:21
5086
|
5187
LL | let ref a @ box ref mut b = Box::new(NC);
5288
| ------------^^^^^^^^^
@@ -58,18 +94,18 @@ LL | drop(a);
5894
| - immutable borrow later used here
5995

6096
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
61-
--> $DIR/borrowck-pat-at-and-box.rs:40:25
97+
--> $DIR/borrowck-pat-at-and-box.rs:43:25
6298
|
6399
LL | let ref mut a @ box ref b = Box::new(NC);
64100
| ----------------^^^^^
65101
| | |
66102
| | immutable borrow occurs here
67103
| mutable borrow occurs here
68-
LL |
104+
...
69105
LL | *a = Box::new(NC);
70106
| -- mutable borrow later used here
71107

72-
error: aborting due to 7 previous errors
108+
error: aborting due to 11 previous errors
73109

74110
Some errors have detailed explanations: E0007, E0009, E0382, E0502.
75111
For more information about an error, try `rustc --explain E0007`.

src/test/ui/pattern/bindings-after-at/borrowck-pat-ref-mut-and-ref.rs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ enum Option<T> {
99
fn main() {
1010
match &mut Some(1) {
1111
ref mut z @ &mut Some(ref a) => {
12-
//~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
12+
//~^ ERROR cannot borrow `z` as immutable because it is also borrowed as mutable
13+
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
1314
**z = None;
1415
println!("{}", *a);
1516
}
@@ -18,30 +19,38 @@ fn main() {
1819

1920
struct U;
2021

21-
let ref a @ ref mut b = U; // FIXME: This should not compile.
22-
let ref mut a @ ref b = U; // FIXME: This should not compile.
23-
let ref a @ (ref mut b, ref mut c) = (U, U); // FIXME: This should not compile.
24-
let ref mut a @ (ref b, ref c) = (U, U); // FIXME: This should not compile.
22+
let ref a @ ref mut b = U;
23+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
24+
let ref mut a @ ref b = U;
25+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
26+
let ref a @ (ref mut b, ref mut c) = (U, U);
27+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
28+
let ref mut a @ (ref b, ref c) = (U, U);
29+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
2530

26-
// FIXME: Seems like we have a soundness hole here.
2731
let ref mut a @ ref b = U;
28-
*a = U; // We are mutating...
29-
drop(b); // ..but at the same time we are holding a live shared borrow.
30-
// FIXME: Inverted; seems like the same issue exists here as well.
32+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
33+
*a = U;
34+
drop(b);
3135
let ref a @ ref mut b = U;
36+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
3237
*b = U;
3338
drop(a);
3439

3540
match Ok(U) {
3641
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
37-
*a = Err(U); // FIXME: ^ should not compile.
42+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
43+
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
44+
*a = Err(U);
3845
drop(b);
3946
}
4047
}
4148

4249
match Ok(U) {
4350
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
44-
//~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
51+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
52+
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
53+
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
4554
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
4655
*b = U;
4756
drop(a);
@@ -50,38 +59,50 @@ fn main() {
5059

5160
match Ok(U) {
5261
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
53-
//~^ ERROR cannot assign to `*b`, as it is immutable for the pattern guard
62+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
63+
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
64+
//~| ERROR cannot assign to `*b`, as it is immutable for the pattern guard
5465
_ => {}
5566
}
5667
match Ok(U) {
5768
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
58-
//~^ ERROR cannot assign to `*a`, as it is immutable for the pattern guard
69+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
70+
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
71+
//~| ERROR cannot assign to `*a`, as it is immutable for the pattern guard
5972
_ => {}
6073
}
6174
match Ok(U) {
6275
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
63-
//~^ ERROR cannot move out of `b` in pattern guard
76+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
77+
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
78+
//~| ERROR cannot move out of `b` in pattern guard
6479
_ => {}
6580
}
6681
match Ok(U) {
6782
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
68-
//~^ ERROR cannot move out of `a` in pattern guard
83+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
84+
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
85+
//~| ERROR cannot move out of `a` in pattern guard
6986
_ => {}
7087
}
7188

7289
let ref a @ (ref mut b, ref mut c) = (U, U);
73-
*b = U; // FIXME: ^ should not compile.
90+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
91+
*b = U;
7492
*c = U;
7593

7694
let ref a @ (ref mut b, ref mut c) = (U, U);
77-
//~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
95+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
96+
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
7897
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
7998
*b = U;
8099
drop(a);
81100

82101
let ref a @ (ref mut b, ref mut c) = (U, U);
83-
*b = U; //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
102+
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
103+
*b = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
84104
*c = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
85105
drop(a);
86-
let ref mut a @ (ref b, ref c) = (U, U); // FIXME: This should not compile.
106+
let ref mut a @ (ref b, ref c) = (U, U);
107+
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
87108
}

0 commit comments

Comments
 (0)