diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-03-27 22:23:10 +0100 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-03-27 22:26:30 +0100 |
| commit | f995003ec5053c85efca895d0506392d3be88286 (patch) | |
| tree | 15d91ed754919a854ab62591f6c7091461b41e86 /tests/ui/closures | |
| parent | dd19135b044cd21a9c3ae7ae87620bf41a208066 (diff) | |
| download | rust-f995003ec5053c85efca895d0506392d3be88286.tar.gz rust-f995003ec5053c85efca895d0506392d3be88286.zip | |
Fix subslice capture in closure
Diffstat (limited to 'tests/ui/closures')
| -rw-r--r-- | tests/ui/closures/2229_closure_analysis/array_subslice.rs | 13 | ||||
| -rw-r--r-- | tests/ui/closures/2229_closure_analysis/array_subslice.stderr | 26 |
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.rs b/tests/ui/closures/2229_closure_analysis/array_subslice.rs new file mode 100644 index 00000000000..5f244ea8936 --- /dev/null +++ b/tests/ui/closures/2229_closure_analysis/array_subslice.rs @@ -0,0 +1,13 @@ +// regression test for #109298 +// edition: 2021 + +pub fn subslice_array(x: [u8; 3]) { + let f = || { + let [_x @ ..] = x; + let [ref y, ref mut z @ ..] = x; //~ ERROR cannot borrow `x[..]` as mutable + }; + + f(); //~ ERROR cannot borrow `f` as mutable +} + +fn main() {} diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr new file mode 100644 index 00000000000..888c60d5e91 --- /dev/null +++ b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr @@ -0,0 +1,26 @@ +error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable + --> $DIR/array_subslice.rs:7:21 + | +LL | pub fn subslice_array(x: [u8; 3]) { + | - help: consider changing this to be mutable: `mut x` +... +LL | let [ref y, ref mut z @ ..] = x; + | ^^^^^^^^^ cannot borrow as mutable + +error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable + --> $DIR/array_subslice.rs:10:5 + | +LL | let [ref y, ref mut z @ ..] = x; + | - calling `f` requires mutable binding due to mutable borrow of `x` +... +LL | f(); + | ^ cannot borrow as mutable + | +help: consider changing this to be mutable + | +LL | let mut f = || { + | +++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0596`. |
