2016-02-27 17:01:15 -06:00
|
|
|
#![feature(plugin)]
|
|
|
|
#![plugin(clippy)]
|
|
|
|
|
|
|
|
#![deny(clippy)]
|
2016-06-05 13:19:00 -05:00
|
|
|
#![allow(blacklisted_name, unused_assignments)]
|
2016-02-27 17:01:15 -06:00
|
|
|
|
2016-02-27 17:46:02 -06:00
|
|
|
struct Foo(u32);
|
|
|
|
|
2016-06-05 13:19:00 -05:00
|
|
|
fn array() {
|
|
|
|
let mut foo = [1, 2];
|
|
|
|
let temp = foo[0];
|
|
|
|
foo[0] = foo[1];
|
|
|
|
foo[1] = temp;
|
|
|
|
//~^^^ ERROR this looks like you are swapping elements of `foo` manually
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION foo.swap(0, 1);
|
|
|
|
|
|
|
|
foo.swap(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn slice() {
|
|
|
|
let foo = &mut [1, 2];
|
|
|
|
let temp = foo[0];
|
|
|
|
foo[0] = foo[1];
|
|
|
|
foo[1] = temp;
|
|
|
|
//~^^^ ERROR this looks like you are swapping elements of `foo` manually
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION foo.swap(0, 1);
|
|
|
|
|
|
|
|
foo.swap(0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn vec() {
|
|
|
|
let mut foo = vec![1, 2];
|
|
|
|
let temp = foo[0];
|
|
|
|
foo[0] = foo[1];
|
|
|
|
foo[1] = temp;
|
|
|
|
//~^^^ ERROR this looks like you are swapping elements of `foo` manually
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION foo.swap(0, 1);
|
|
|
|
|
|
|
|
foo.swap(0, 1);
|
|
|
|
}
|
|
|
|
|
2016-02-27 17:01:15 -06:00
|
|
|
fn main() {
|
2016-06-05 13:19:00 -05:00
|
|
|
array();
|
|
|
|
slice();
|
|
|
|
vec();
|
|
|
|
|
2016-02-27 17:01:15 -06:00
|
|
|
let mut a = 42;
|
|
|
|
let mut b = 1337;
|
|
|
|
|
|
|
|
a = b;
|
|
|
|
b = a;
|
|
|
|
//~^^ ERROR this looks like you are trying to swap `a` and `b`
|
|
|
|
//~| HELP try
|
2016-02-27 17:46:02 -06:00
|
|
|
//~| SUGGESTION std::mem::swap(&mut a, &mut b);
|
|
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
|
2016-06-05 11:07:12 -05:00
|
|
|
; let t = a;
|
2016-02-27 17:46:02 -06:00
|
|
|
a = b;
|
|
|
|
b = t;
|
|
|
|
//~^^^ ERROR this looks like you are swapping `a` and `b` manually
|
|
|
|
//~| HELP try
|
2016-06-05 11:07:12 -05:00
|
|
|
//~| SUGGESTION ; std::mem::swap(&mut a, &mut b);
|
2016-02-27 17:46:02 -06:00
|
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
|
|
|
|
let mut c = Foo(42);
|
|
|
|
|
|
|
|
c.0 = a;
|
|
|
|
a = c.0;
|
|
|
|
//~^^ ERROR this looks like you are trying to swap `c.0` and `a`
|
|
|
|
//~| HELP try
|
|
|
|
//~| SUGGESTION std::mem::swap(&mut c.0, &mut a);
|
|
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
|
2016-06-05 11:07:12 -05:00
|
|
|
; let t = c.0;
|
2016-02-27 17:46:02 -06:00
|
|
|
c.0 = a;
|
|
|
|
a = t;
|
|
|
|
//~^^^ ERROR this looks like you are swapping `c.0` and `a` manually
|
|
|
|
//~| HELP try
|
2016-06-05 11:07:12 -05:00
|
|
|
//~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a);
|
2016-02-27 17:01:15 -06:00
|
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
}
|