1 // This tests that we can't modify Box<&mut T> contents while they
2 // are borrowed (#14498).
4 // Also includes tests of the errors reported when the Box in question
5 // is immutable (#14270).
10 struct B<'a> { a: Box<&'a mut isize> }
12 fn indirect_write_to_imm_box() {
14 let y: Box<_> = Box::new(&mut x);
16 ***p = 2; //~ ERROR cannot assign to `***p`
20 fn borrow_in_var_from_var() {
22 let mut y: Box<_> = Box::new(&mut x);
25 **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
30 fn borrow_in_var_from_var_via_imm_box() {
32 let y: Box<_> = Box::new(&mut x);
35 **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
40 fn borrow_in_var_from_field() {
41 let mut x = A { a: 1 };
42 let mut y: Box<_> = Box::new(&mut x.a);
45 **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
50 fn borrow_in_var_from_field_via_imm_box() {
51 let mut x = A { a: 1 };
52 let y: Box<_> = Box::new(&mut x.a);
55 **y = 2; //~ ERROR cannot assign to `**y` because it is borrowed
60 fn borrow_in_field_from_var() {
62 let mut y = B { a: Box::new(&mut x) };
65 **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
70 fn borrow_in_field_from_var_via_imm_box() {
72 let y = B { a: Box::new(&mut x) };
75 **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
80 fn borrow_in_field_from_field() {
81 let mut x = A { a: 1 };
82 let mut y = B { a: Box::new(&mut x.a) };
85 **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
90 fn borrow_in_field_from_field_via_imm_box() {
91 let mut x = A { a: 1 };
92 let y = B { a: Box::new(&mut x.a) };
95 **y.a = 2; //~ ERROR cannot assign to `**y.a` because it is borrowed
101 indirect_write_to_imm_box();
102 borrow_in_var_from_var();
103 borrow_in_var_from_var_via_imm_box();
104 borrow_in_var_from_field();
105 borrow_in_var_from_field_via_imm_box();
106 borrow_in_field_from_var();
107 borrow_in_field_from_var_via_imm_box();
108 borrow_in_field_from_field();
109 borrow_in_field_from_field_via_imm_box();