File tree Expand file tree Collapse file tree 3 files changed +41
-3
lines changed
compiler/rustc_hir_typeck/src
tests/ui/closures/2229_closure_analysis Expand file tree Collapse file tree 3 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -1893,14 +1893,13 @@ fn restrict_capture_precision(
18931893
18941894 for ( i, proj) in place. projections . iter ( ) . enumerate ( ) {
18951895 match proj. kind {
1896- ProjectionKind :: Index => {
1897- // Arrays are completely captured, so we drop Index projections
1896+ ProjectionKind :: Index | ProjectionKind :: Subslice => {
1897+ // Arrays are completely captured, so we drop Index and Subslice projections
18981898 truncate_place_to_len_and_update_capture_kind ( & mut place, & mut curr_mode, i) ;
18991899 return ( place, curr_mode) ;
19001900 }
19011901 ProjectionKind :: Deref => { }
19021902 ProjectionKind :: Field ( ..) => { } // ignore
1903- ProjectionKind :: Subslice => { } // We never capture this
19041903 }
19051904 }
19061905
Original file line number Diff line number Diff line change 1+ // regression test for #109298
2+ // edition: 2021
3+
4+ pub fn subslice_array ( x : [ u8 ; 3 ] ) {
5+ let f = || {
6+ let [ _x @ ..] = x;
7+ let [ ref y, ref mut z @ ..] = x; //~ ERROR cannot borrow `x[..]` as mutable
8+ } ;
9+
10+ f ( ) ; //~ ERROR cannot borrow `f` as mutable
11+ }
12+
13+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable
2+ --> $DIR/array_subslice.rs:7:21
3+ |
4+ LL | pub fn subslice_array(x: [u8; 3]) {
5+ | - help: consider changing this to be mutable: `mut x`
6+ ...
7+ LL | let [ref y, ref mut z @ ..] = x;
8+ | ^^^^^^^^^ cannot borrow as mutable
9+
10+ error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
11+ --> $DIR/array_subslice.rs:10:5
12+ |
13+ LL | let [ref y, ref mut z @ ..] = x;
14+ | - calling `f` requires mutable binding due to mutable borrow of `x`
15+ ...
16+ LL | f();
17+ | ^ cannot borrow as mutable
18+ |
19+ help: consider changing this to be mutable
20+ |
21+ LL | let mut f = || {
22+ | +++
23+
24+ error: aborting due to 2 previous errors
25+
26+ For more information about this error, try `rustc --explain E0596`.
You can’t perform that action at this time.
0 commit comments