rust/compiler/rustc_borrowck/src
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
..
constraints Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
diagnostics Rollup merge of #111403 - y21:suggest-slice-swap, r=compiler-errors 2023-06-30 08:01:12 +02:00
region_infer s/Clause/ClauseKind 2023-06-19 14:57:42 +00:00
type_check Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino 2023-06-27 00:34:49 +00:00
util Move some utils out of rustc_const_eval 2023-04-16 12:05:54 +02:00
borrow_set.rs address most easy comments 2023-06-20 20:55:31 +08:00
borrowck_errors.rs avoid &format in error message code 2023-06-23 02:17:39 +09:00
constraint_generation.rs Remove default visitor impl in region constraint generation 2023-06-06 19:00:47 +00:00
consumers.rs Move DefiningAnchor 2023-05-25 03:21:21 +00:00
dataflow.rs Rollup merge of #112236 - cjgillot:interval-kill, r=davidtwco 2023-06-28 18:28:46 +05:30
def_use.rs unique borrows are mutating uses 2023-05-29 17:15:48 +02:00
facts.rs Various minor Idx-related tweaks 2023-04-16 02:42:50 -07:00
invalidation.rs merge BorrowKind::Unique into BorrowKind::Mut 2023-06-20 20:55:31 +08:00
lib.rs address most easy comments 2023-06-20 20:55:31 +08:00
location.rs Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
member_constraints.rs remove unused muts 2023-04-28 20:19:48 +02:00
nll.rs Rename tcx.mk_re_* => Region::new_* 2023-05-29 17:54:53 +00:00
path_utils.rs Move mir::Fieldabi::FieldIdx 2023-03-28 22:22:37 -07:00
place_ext.rs use PlaceRef abstractions more consistently 2023-06-25 20:38:01 -04:00
places_conflict.rs Auto merge of #112693 - ericmarkmartin:use-more-placeref, r=spastorino 2023-06-27 00:34:49 +00:00
prefixes.rs lint auto pass 2022-11-09 20:42:16 +08:00
renumber.rs check array type of repeat exprs is wf 2023-05-04 11:22:40 +01:00
session_diagnostics.rs Don't call await a method 2023-04-27 17:18:12 +00:00
universal_regions.rs Rename tcx.mk_re_* => Region::new_* 2023-05-29 17:54:53 +00:00
used_muts.rs Rollup merge of #108856 - Zeegomo:remove-drop-and-rep, r=tmiasko 2023-03-08 21:26:51 +01:00