3 // Test that arrays are completely captured by closures by relying on the borrow check diagnostics
6 let mut arr = [1, 2, 3, 4, 5];
12 // c will capture `arr` completely, therefore another index into the
13 // array can't be modified here
15 //~^ ERROR: cannot use `arr` because it was mutably borrowed
16 //~| ERROR: cannot use `arr[_]` because it was mutably borrowed
21 let mut arr = [1, 2, 3, 4, 5];
24 println!("{:#?}", &arr[3..4]);
27 // c will capture `arr` completely, therefore another index into the
28 // array can't be modified here
30 //~^ ERROR: cannot assign to `arr[_]` because it is borrowed
35 let mut arr = [1, 2, 3, 4, 5];
38 println!("{}", arr[3]);
41 // c will capture `arr` completely, therefore another index into the
42 // array can't be modified here
44 //~^ ERROR: cannot assign to `arr[_]` because it is borrowed
49 let mut arr = [1, 2, 3, 4, 5];
55 // c will capture `arr` completely, therefore we cannot borrow another index
57 println!("{}", arr[3]);
58 //~^ ERROR: cannot use `arr` because it was mutably borrowed
59 //~| ERROR: cannot borrow `arr[_]` as immutable because it is also borrowed as mutable
65 let mut arr = [1, 2, 3, 4, 5];
71 // c will capture `arr` completely, therefore we cannot borrow other indices
73 println!("{:#?}", &arr[3..2]);
74 //~^ ERROR: cannot borrow `arr` as immutable because it is also borrowed as mutable