struct Foo(u32);
+#[derive(Clone)]
+struct Bar {
+ a: u32,
+ b: u32,
+}
+
+fn field() {
+ let mut bar = Bar { a: 1, b: 2 };
+
+ let temp = bar.a;
+ bar.a = bar.b;
+ bar.b = temp;
+
+ let mut baz = vec![bar.clone(), bar.clone()];
+ let temp = baz[0].a;
+ baz[0].a = baz[1].a;
+ baz[1].a = temp;
+}
+
fn array() {
let mut foo = [1, 2];
let temp = foo[0];
#[rustfmt::skip]
fn main() {
+ field();
array();
slice();
vec();
error: this looks like you are swapping elements of `foo` manually
- --> $DIR/swap.rs:8:5
+ --> $DIR/swap.rs:27:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
= note: `-D clippy::manual-swap` implied by `-D warnings`
error: this looks like you are swapping elements of `foo` manually
- --> $DIR/swap.rs:17:5
+ --> $DIR/swap.rs:36:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
| |_________________^ help: try: `foo.swap(0, 1)`
error: this looks like you are swapping elements of `foo` manually
- --> $DIR/swap.rs:26:5
+ --> $DIR/swap.rs:45:5
|
LL | / let temp = foo[0];
LL | | foo[0] = foo[1];
| |_________________^ help: try: `foo.swap(0, 1)`
error: this looks like you are swapping `a` and `b` manually
- --> $DIR/swap.rs:45:7
+ --> $DIR/swap.rs:65:7
|
LL | ; let t = a;
| _______^
= note: or maybe you should use `std::mem::replace`?
error: this looks like you are swapping `c.0` and `a` manually
- --> $DIR/swap.rs:54:7
+ --> $DIR/swap.rs:74:7
|
LL | ; let t = c.0;
| _______^
= note: or maybe you should use `std::mem::replace`?
error: this looks like you are trying to swap `a` and `b`
- --> $DIR/swap.rs:42:5
+ --> $DIR/swap.rs:62:5
|
LL | / a = b;
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:51:5
+ --> $DIR/swap.rs:71:5
|
LL | / c.0 = a;
LL | | a = c.0;