Files
rust/tests/ui
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-04-30 00:06:26 +08:00
2023-01-30 20:12:19 +00:00
2023-01-15 19:46:20 +00:00
2023-06-19 15:39:55 +02:00
2023-05-24 19:35:59 -03:00
2023-05-30 12:40:35 +02:00
2023-05-30 13:03:40 +02:00
2023-04-03 09:24:11 +02:00
2023-05-08 17:58:01 -03:00
2023-05-26 06:55:06 +10:00
2023-05-04 18:06:07 +00:00
2023-05-11 12:14:57 -07:00
2023-05-08 17:58:01 -03:00
2023-06-23 16:26:22 +00:00
2023-06-27 21:36:15 +00:00
2023-01-30 20:12:19 +00:00
2023-06-19 20:00:41 +00:00
2023-06-10 14:46:11 -04:00
2023-05-25 17:40:46 +00:00
2023-06-28 07:59:36 -04:00
2023-02-16 11:42:35 -03:00
2023-05-08 03:36:30 +00:00
2023-05-12 00:10:52 +00:00
2023-04-29 13:01:46 +01:00
2023-06-28 01:51:53 -04:00
2023-06-29 16:24:07 +03:00
2023-06-26 08:56:32 +00:00
2023-04-03 09:24:11 +02:00
2023-05-05 14:58:52 -07:00
2023-06-24 21:49:38 -04:00
2023-06-06 18:43:20 +00:00
2023-04-19 19:13:45 +00:00
2023-04-13 22:10:26 -05:00
2023-06-20 19:46:01 -04:00
2023-05-08 03:36:30 +00:00
2023-05-29 12:07:41 -03:00
2023-03-29 18:04:44 -04:00
2023-05-26 18:55:02 +01:00
2023-04-26 21:02:56 +02:00
2023-06-12 20:24:48 +08:00
2023-06-26 08:56:32 +00:00
2023-05-01 16:15:17 +08:00
2023-04-29 13:01:46 +01:00
2023-06-22 23:01:48 +02:00
2023-05-12 00:10:52 +00:00
2023-05-24 19:35:59 -03:00
2023-01-15 19:46:20 +00:00
2023-01-15 19:46:20 +00:00
2023-03-08 00:00:18 +00:00
2023-04-13 22:10:26 -05:00
2023-04-13 22:10:26 -05:00
2023-03-08 00:00:18 +00:00
2023-03-08 00:00:18 +00:00
2023-01-15 19:46:20 +00:00