Skip to content

Commit a1495b7

Browse files
committed
---
yaml --- r: 196141 b: refs/heads/tmp c: e434053 h: refs/heads/master i: 196139: 51831ce v: v3
1 parent cfaa7b5 commit a1495b7

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3232
refs/heads/beta: 9854143cba679834bc4ef932858cd5303f015a0e
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
35-
refs/heads/tmp: f513380cf51eb5fd977b8815a7acd999e424dc93
35+
refs/heads/tmp: e4340531c2af4b39b5ee7c111fae4f6f27ac8bf7
3636
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3737
refs/tags/homu-tmp: 53a183f0274316596bf9405944d4f0468d8c93e4
3838
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

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

Lines changed: 61 additions & 1 deletion
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)