mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Add regression test for manual_swap
This commit is contained in:
parent
7a943a9dfc
commit
d3232b0fce
@ -46,6 +46,15 @@ fn slice() {
|
||||
foo.swap(0, 1);
|
||||
}
|
||||
|
||||
fn unswappable_slice() {
|
||||
let foo = &mut [vec![1, 2], vec![3, 4]];
|
||||
let temp = foo[0][1];
|
||||
foo[0][1] = foo[1][0];
|
||||
foo[1][0] = temp;
|
||||
|
||||
// swap(foo[0][1], foo[1][0]) would fail
|
||||
}
|
||||
|
||||
fn vec() {
|
||||
let mut foo = vec![1, 2];
|
||||
let temp = foo[0];
|
||||
|
@ -17,7 +17,7 @@ LL | | foo[1] = temp;
|
||||
| |_________________^ help: try: `foo.swap(0, 1)`
|
||||
|
||||
error: this looks like you are swapping elements of `foo` manually
|
||||
--> $DIR/swap.rs:51:5
|
||||
--> $DIR/swap.rs:60:5
|
||||
|
|
||||
LL | / let temp = foo[0];
|
||||
LL | | foo[0] = foo[1];
|
||||
@ -25,7 +25,7 @@ LL | | foo[1] = temp;
|
||||
| |_________________^ help: try: `foo.swap(0, 1)`
|
||||
|
||||
error: this looks like you are swapping `a` and `b` manually
|
||||
--> $DIR/swap.rs:71:7
|
||||
--> $DIR/swap.rs:80:7
|
||||
|
|
||||
LL | ; let t = a;
|
||||
| _______^
|
||||
@ -36,7 +36,7 @@ LL | | b = t;
|
||||
= note: or maybe you should use `std::mem::replace`?
|
||||
|
||||
error: this looks like you are swapping `c.0` and `a` manually
|
||||
--> $DIR/swap.rs:80:7
|
||||
--> $DIR/swap.rs:89:7
|
||||
|
|
||||
LL | ; let t = c.0;
|
||||
| _______^
|
||||
@ -47,7 +47,7 @@ LL | | a = t;
|
||||
= note: or maybe you should use `std::mem::replace`?
|
||||
|
||||
error: this looks like you are trying to swap `a` and `b`
|
||||
--> $DIR/swap.rs:68:5
|
||||
--> $DIR/swap.rs:77:5
|
||||
|
|
||||
LL | / a = b;
|
||||
LL | | b = a;
|
||||
@ -57,7 +57,7 @@ LL | | b = a;
|
||||
= note: or maybe you should use `std::mem::replace`?
|
||||
|
||||
error: this looks like you are trying to swap `c.0` and `a`
|
||||
--> $DIR/swap.rs:77:5
|
||||
--> $DIR/swap.rs:86:5
|
||||
|
|
||||
LL | / c.0 = a;
|
||||
LL | | a = c.0;
|
||||
|
Loading…
Reference in New Issue
Block a user