mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
84 lines
2 KiB
Rust
84 lines
2 KiB
Rust
#![feature(plugin)]
|
|
#![plugin(clippy)]
|
|
|
|
#![deny(clippy)]
|
|
#![allow(blacklisted_name, unused_assignments)]
|
|
|
|
struct Foo(u32);
|
|
|
|
fn array() {
|
|
let mut foo = [1, 2];
|
|
let temp = foo[0]; //~ NOTE implied by
|
|
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]; //~ NOTE implied by
|
|
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]; //~ NOTE implied by
|
|
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 main() {
|
|
array();
|
|
slice();
|
|
vec();
|
|
|
|
let mut a = 42;
|
|
let mut b = 1337;
|
|
|
|
a = b; //~ NOTE implied by
|
|
b = a;
|
|
//~^^ ERROR this looks like you are trying to swap `a` and `b`
|
|
//~| HELP try
|
|
//~| SUGGESTION std::mem::swap(&mut a, &mut b);
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
; let t = a; //~ NOTE implied by
|
|
a = b;
|
|
b = t;
|
|
//~^^^ ERROR this looks like you are swapping `a` and `b` manually
|
|
//~| HELP try
|
|
//~| SUGGESTION ; std::mem::swap(&mut a, &mut b);
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
|
|
let mut c = Foo(42);
|
|
|
|
c.0 = a; //~ NOTE implied by
|
|
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`?
|
|
|
|
; let t = c.0; //~ NOTE implied by
|
|
c.0 = a;
|
|
a = t;
|
|
//~^^^ ERROR this looks like you are swapping `c.0` and `a` manually
|
|
//~| HELP try
|
|
//~| SUGGESTION ; std::mem::swap(&mut c.0, &mut a);
|
|
//~| NOTE or maybe you should use `std::mem::replace`?
|
|
}
|