Skip to content

Commit e434053

Browse files
committed
Fallout to test.
1 parent f513380 commit e434053

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

src/test/compile-fail/borrowck-issue-14498.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -9,56 +9,116 @@
99
// except according to those terms.
1010

1111
// This tests that we can't modify Box<&mut T> contents while they
12-
// are borrowed.
12+
// are borrowed (#14498).
13+
//
14+
// Also includes tests of the errors reported when the Box in question
15+
// is immutable (#14270).
1316

1417
#![feature(box_syntax)]
1518

1619
struct A { a: isize }
1720
struct B<'a> { a: Box<&'a mut isize> }
1821

22+
fn indirect_write_to_imm_box() {
23+
let mut x: isize = 1;
24+
let y: Box<_> = box &mut x;
25+
let p = &y;
26+
***p = 2; //~ ERROR cannot assign to data in an immutable container
27+
drop(p);
28+
}
29+
1930
fn borrow_in_var_from_var() {
31+
let mut x: isize = 1;
32+
let mut y: Box<_> = box &mut x;
33+
let p = &y;
34+
let q = &***p;
35+
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
36+
drop(p);
37+
drop(q);
38+
}
39+
40+
fn borrow_in_var_from_var_via_imm_box() {
2041
let mut x: isize = 1;
2142
let y: Box<_> = box &mut x;
2243
let p = &y;
2344
let q = &***p;
2445
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
46+
//~^ ERROR cannot assign to data in an immutable container
2547
drop(p);
2648
drop(q);
2749
}
2850

2951
fn borrow_in_var_from_field() {
52+
let mut x = A { a: 1 };
53+
let mut y: Box<_> = box &mut x.a;
54+
let p = &y;
55+
let q = &***p;
56+
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
57+
drop(p);
58+
drop(q);
59+
}
60+
61+
fn borrow_in_var_from_field_via_imm_box() {
3062
let mut x = A { a: 1 };
3163
let y: Box<_> = box &mut x.a;
3264
let p = &y;
3365
let q = &***p;
3466
**y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
67+
//~^ ERROR cannot assign to data in an immutable container
3568
drop(p);
3669
drop(q);
3770
}
3871

3972
fn borrow_in_field_from_var() {
73+
let mut x: isize = 1;
74+
let mut y = B { a: box &mut x };
75+
let p = &y.a;
76+
let q = &***p;
77+
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
78+
drop(p);
79+
drop(q);
80+
}
81+
82+
fn borrow_in_field_from_var_via_imm_box() {
4083
let mut x: isize = 1;
4184
let y = B { a: box &mut x };
4285
let p = &y.a;
4386
let q = &***p;
4487
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
88+
//~^ ERROR cannot assign to data in an immutable container
4589
drop(p);
4690
drop(q);
4791
}
4892

4993
fn borrow_in_field_from_field() {
94+
let mut x = A { a: 1 };
95+
let mut y = B { a: box &mut x.a };
96+
let p = &y.a;
97+
let q = &***p;
98+
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
99+
drop(p);
100+
drop(q);
101+
}
102+
103+
fn borrow_in_field_from_field_via_imm_box() {
50104
let mut x = A { a: 1 };
51105
let y = B { a: box &mut x.a };
52106
let p = &y.a;
53107
let q = &***p;
54108
**y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
109+
//~^ ERROR cannot assign to data in an immutable container
55110
drop(p);
56111
drop(q);
57112
}
58113

59114
fn main() {
115+
indirect_write_to_imm_box();
60116
borrow_in_var_from_var();
117+
borrow_in_var_from_var_via_imm_box();
61118
borrow_in_var_from_field();
119+
borrow_in_var_from_field_via_imm_box();
62120
borrow_in_field_from_var();
121+
borrow_in_field_from_var_via_imm_box();
63122
borrow_in_field_from_field();
123+
borrow_in_field_from_field_via_imm_box();
64124
}

0 commit comments

Comments
 (0)