diff options
| author | sjwang05 <63834813+sjwang05@users.noreply.github.com> | 2024-01-11 21:02:43 -0800 |
|---|---|---|
| committer | sjwang05 <63834813+sjwang05@users.noreply.github.com> | 2024-01-19 01:30:46 -0800 |
| commit | f9faf161817eef2b885bd47908ceaeef675ea72f (patch) | |
| tree | 1a56a5d2a70c27b4e575d12f2ecca26b8a6f8091 /tests | |
| parent | e9271846294c4ee5bd7706df68180320c0b5ff20 (diff) | |
Suggest .swap() instead of mem::swap() in more cases
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/suggestions/suggest-slice-swap.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/suggestions/suggest-slice-swap.rs | 9 | ||||
| -rw-r--r-- | tests/ui/suggestions/suggest-slice-swap.stderr | 17 |
3 files changed, 35 insertions, 0 deletions
diff --git a/tests/ui/suggestions/suggest-slice-swap.fixed b/tests/ui/suggestions/suggest-slice-swap.fixed new file mode 100644 index 00000000000..05b7ec26379 --- /dev/null +++ b/tests/ui/suggestions/suggest-slice-swap.fixed @@ -0,0 +1,9 @@ +// run-rustfix +#![allow(dead_code)] + +fn swap(arr: &mut [u32; 2]) { + arr.swap(1, 0); + //~^ ERROR cannot borrow `arr[_]` as mutable more than once at a time +} + +fn main() {} diff --git a/tests/ui/suggestions/suggest-slice-swap.rs b/tests/ui/suggestions/suggest-slice-swap.rs new file mode 100644 index 00000000000..9f3659aac16 --- /dev/null +++ b/tests/ui/suggestions/suggest-slice-swap.rs @@ -0,0 +1,9 @@ +// run-rustfix +#![allow(dead_code)] + +fn swap(arr: &mut [u32; 2]) { + std::mem::swap(&mut arr[0], &mut arr[1]); + //~^ ERROR cannot borrow `arr[_]` as mutable more than once at a time +} + +fn main() {} diff --git a/tests/ui/suggestions/suggest-slice-swap.stderr b/tests/ui/suggestions/suggest-slice-swap.stderr new file mode 100644 index 00000000000..2840fc0a761 --- /dev/null +++ b/tests/ui/suggestions/suggest-slice-swap.stderr @@ -0,0 +1,17 @@ +error[E0499]: cannot borrow `arr[_]` as mutable more than once at a time + --> $DIR/suggest-slice-swap.rs:5:33 + | +LL | std::mem::swap(&mut arr[0], &mut arr[1]); + | -------------- ----------- ^^^^^^^^^^^ second mutable borrow occurs here + | | | + | | first mutable borrow occurs here + | first borrow later used by call + | +help: use `.swap()` to swap elements at the specified indices instead + | +LL | arr.swap(1, 0); + | ~~~~~~~~~~~~~~ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. |
