Skip to content

Commit d3232b0

Browse files
committed
Add regression test for manual_swap
1 parent 7a943a9 commit d3232b0

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tests/ui/swap.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ fn slice() {
4646
foo.swap(0, 1);
4747
}
4848

49+
fn unswappable_slice() {
50+
let foo = &mut [vec![1, 2], vec![3, 4]];
51+
let temp = foo[0][1];
52+
foo[0][1] = foo[1][0];
53+
foo[1][0] = temp;
54+
55+
// swap(foo[0][1], foo[1][0]) would fail
56+
}
57+
4958
fn vec() {
5059
let mut foo = vec![1, 2];
5160
let temp = foo[0];

tests/ui/swap.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ LL | | foo[1] = temp;
1717
| |_________________^ help: try: `foo.swap(0, 1)`
1818

1919
error: this looks like you are swapping elements of `foo` manually
20-
--> $DIR/swap.rs:51:5
20+
--> $DIR/swap.rs:60:5
2121
|
2222
LL | / let temp = foo[0];
2323
LL | | foo[0] = foo[1];
2424
LL | | foo[1] = temp;
2525
| |_________________^ help: try: `foo.swap(0, 1)`
2626

2727
error: this looks like you are swapping `a` and `b` manually
28-
--> $DIR/swap.rs:71:7
28+
--> $DIR/swap.rs:80:7
2929
|
3030
LL | ; let t = a;
3131
| _______^
@@ -36,7 +36,7 @@ LL | | b = t;
3636
= note: or maybe you should use `std::mem::replace`?
3737

3838
error: this looks like you are swapping `c.0` and `a` manually
39-
--> $DIR/swap.rs:80:7
39+
--> $DIR/swap.rs:89:7
4040
|
4141
LL | ; let t = c.0;
4242
| _______^
@@ -47,7 +47,7 @@ LL | | a = t;
4747
= note: or maybe you should use `std::mem::replace`?
4848

4949
error: this looks like you are trying to swap `a` and `b`
50-
--> $DIR/swap.rs:68:5
50+
--> $DIR/swap.rs:77:5
5151
|
5252
LL | / a = b;
5353
LL | | b = a;
@@ -57,7 +57,7 @@ LL | | b = a;
5757
= note: or maybe you should use `std::mem::replace`?
5858

5959
error: this looks like you are trying to swap `c.0` and `a`
60-
--> $DIR/swap.rs:77:5
60+
--> $DIR/swap.rs:86:5
6161
|
6262
LL | / c.0 = a;
6363
LL | | a = c.0;

0 commit comments

Comments
 (0)