Commit 386236f
committed
Detect borrow error involving sub-slices and suggest
```
error[E0499]: cannot borrow `foo` as mutable more than once at a time
--> $DIR/suggest-split-at-mut.rs:13:18
|
LL | let a = &mut foo[..2];
| --- first mutable borrow occurs here
LL | let b = &mut foo[2..];
| ^^^ second mutable borrow occurs here
LL | a[0] = 5;
| ---- first borrow later used here
|
= help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```
Address most of #58792.
For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.split_at_mut
1 parent 6a9758d commit 386236f
File tree
4 files changed
+57
-18
lines changed- compiler/rustc_borrowck/src/diagnostics
- tests/ui
- borrowck
- suggestions
4 files changed
+57
-18
lines changedLines changed: 25 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1581 | 1581 | | |
1582 | 1582 | | |
1583 | 1583 | | |
| 1584 | + | |
| 1585 | + | |
1584 | 1586 | | |
1585 | 1587 | | |
1586 | 1588 | | |
| |||
2011 | 2013 | | |
2012 | 2014 | | |
2013 | 2015 | | |
| 2016 | + | |
| 2017 | + | |
2014 | 2018 | | |
2015 | 2019 | | |
2016 | 2020 | | |
2017 | | - | |
2018 | 2021 | | |
2019 | 2022 | | |
2020 | 2023 | | |
| |||
2023 | 2026 | | |
2024 | 2027 | | |
2025 | 2028 | | |
2026 | | - | |
2027 | | - | |
| 2029 | + | |
| 2030 | + | |
2028 | 2031 | | |
2029 | | - | |
2030 | | - | |
2031 | | - | |
2032 | | - | |
2033 | | - | |
2034 | | - | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
2035 | 2036 | | |
2036 | 2037 | | |
2037 | | - | |
2038 | | - | |
2039 | | - | |
2040 | | - | |
| 2038 | + | |
| 2039 | + | |
2041 | 2040 | | |
2042 | 2041 | | |
2043 | 2042 | | |
2044 | 2043 | | |
2045 | | - | |
2046 | | - | |
2047 | | - | |
| 2044 | + | |
| 2045 | + | |
2048 | 2046 | | |
2049 | 2047 | | |
2050 | 2048 | | |
| |||
2102 | 2100 | | |
2103 | 2101 | | |
2104 | 2102 | | |
| 2103 | + | |
2105 | 2104 | | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
2106 | 2115 | | |
2107 | 2116 | | |
2108 | 2117 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
30 | 34 | | |
31 | 35 | | |
32 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
15 | 27 | | |
16 | 28 | | |
0 commit comments