unnecessary_operation: make test rustfixable

This commit is contained in:
Manish Goregaokar 2019-09-25 10:49:56 -07:00
parent 04dd580f37
commit b94f2e89fd
3 changed files with 112 additions and 27 deletions

View File

@ -0,0 +1,79 @@
// run-rustfix
#![feature(box_syntax)]
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
#![warn(clippy::unnecessary_operation)]
struct Tuple(i32);
struct Struct {
field: i32,
}
enum Enum {
Tuple(i32),
Struct { field: i32 },
}
struct DropStruct {
field: i32,
}
impl Drop for DropStruct {
fn drop(&mut self) {}
}
struct DropTuple(i32);
impl Drop for DropTuple {
fn drop(&mut self) {}
}
enum DropEnum {
Tuple(i32),
Struct { field: i32 },
}
impl Drop for DropEnum {
fn drop(&mut self) {}
}
struct FooString {
s: String,
}
fn get_number() -> i32 {
0
}
fn get_usize() -> usize {
0
}
fn get_struct() -> Struct {
Struct { field: 0 }
}
fn get_drop_struct() -> DropStruct {
DropStruct { field: 0 }
}
fn main() {
get_number();
get_number();
get_struct();
get_number();
get_number();
5;get_number();
get_number();
get_number();
5;6;get_number();
get_number();
get_number();
get_number();
5;get_number();
42;get_number();
[42, 55];get_usize();
42;get_number();
get_number();
[42; 55];get_usize();
get_number();
String::from("blah");
// Do not warn
DropTuple(get_number());
DropStruct { field: get_number() };
DropStruct { field: get_number() };
DropStruct { ..get_drop_struct() };
DropEnum::Tuple(get_number());
DropEnum::Struct { field: get_number() };
}

View File

@ -1,5 +1,7 @@
// run-rustfix
#![feature(box_syntax)]
#![allow(clippy::deref_addrof)]
#![allow(clippy::deref_addrof, dead_code, unused, clippy::no_effect)]
#![warn(clippy::unnecessary_operation)]
struct Tuple(i32);
@ -34,6 +36,10 @@ struct FooString {
fn get_number() -> i32 {
0
}
fn get_usize() -> usize {
0
}
fn get_struct() -> Struct {
Struct { field: 0 }
}
@ -56,10 +62,10 @@ fn main() {
..get_number();
5..get_number();
[42, get_number()];
[42, 55][get_number() as usize];
[42, 55][get_usize()];
(42, get_number()).1;
[get_number(); 55];
[42; 55][get_number() as usize];
[42; 55][get_usize()];
{
get_number()
};

View File

@ -1,5 +1,5 @@
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:45:5
--> $DIR/unnecessary_operation.rs:51:5
|
LL | Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
@ -7,109 +7,109 @@ LL | Tuple(get_number());
= note: `-D clippy::unnecessary-operation` implied by `-D warnings`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:46:5
--> $DIR/unnecessary_operation.rs:52:5
|
LL | Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:47:5
--> $DIR/unnecessary_operation.rs:53:5
|
LL | Struct { ..get_struct() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_struct();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:48:5
--> $DIR/unnecessary_operation.rs:54:5
|
LL | Enum::Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:49:5
--> $DIR/unnecessary_operation.rs:55:5
|
LL | Enum::Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:50:5
--> $DIR/unnecessary_operation.rs:56:5
|
LL | 5 + get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:51:5
--> $DIR/unnecessary_operation.rs:57:5
|
LL | *&get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:52:5
--> $DIR/unnecessary_operation.rs:58:5
|
LL | &get_number();
| ^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:53:5
--> $DIR/unnecessary_operation.rs:59:5
|
LL | (5, 6, get_number());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `5;6;get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:54:5
--> $DIR/unnecessary_operation.rs:60:5
|
LL | box get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:55:5
--> $DIR/unnecessary_operation.rs:61:5
|
LL | get_number()..;
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:56:5
--> $DIR/unnecessary_operation.rs:62:5
|
LL | ..get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:57:5
--> $DIR/unnecessary_operation.rs:63:5
|
LL | 5..get_number();
| ^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:58:5
--> $DIR/unnecessary_operation.rs:64:5
|
LL | [42, get_number()];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:59:5
--> $DIR/unnecessary_operation.rs:65:5
|
LL | [42, 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_number() as usize;`
LL | [42, 55][get_usize()];
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_usize();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:60:5
--> $DIR/unnecessary_operation.rs:66:5
|
LL | (42, get_number()).1;
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:61:5
--> $DIR/unnecessary_operation.rs:67:5
|
LL | [get_number(); 55];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:62:5
--> $DIR/unnecessary_operation.rs:68:5
|
LL | [42; 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_number() as usize;`
LL | [42; 55][get_usize()];
| ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_usize();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:63:5
--> $DIR/unnecessary_operation.rs:69:5
|
LL | / {
LL | | get_number()
@ -117,7 +117,7 @@ LL | | };
| |______^ help: replace it with: `get_number();`
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:66:5
--> $DIR/unnecessary_operation.rs:72:5
|
LL | / FooString {
LL | | s: String::from("blah"),