rust/tests/ui/suggestions
Matthias Krüger 6c22e0419f
Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errors
suggest `slice::swap` for `mem::swap(&mut x[0], &mut x[1])` borrowck error

Recently saw someone ask why this code (example slightly modified):
```rs
fn main() {
  let mut foo = [1, 2];
  std::mem::swap(&mut foo[0], &mut foo[1]);
}
```
triggers this error and how to fix it:
```
error[E0499]: cannot borrow `foo[_]` as mutable more than once at a time
 --> src/main.rs:4:33
  |
4 |     std::mem::swap(&mut foo[0], &mut foo[1]);
  |     -------------- -----------  ^^^^^^^^^^^ second mutable borrow occurs here
  |     |              |
  |     |              first mutable borrow occurs here
  |     first borrow later used by call
  |
  = help: consider using `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices
```
The current help message is nice and goes in the right direction, but I think we can do better for this specific instance and suggest `slice::swap`, which makes this compile
2023-06-30 08:01:12 +02:00
..
2023-05-02 14:48:39 +00:00
2023-05-19 20:58:06 +02:00
2023-04-27 17:18:11 +00:00
2023-05-19 20:58:06 +02:00
2023-05-01 16:15:13 +08:00
2023-05-01 16:15:13 +08:00
2023-05-08 03:36:30 +00:00
2023-05-01 16:15:13 +08:00