Skip to content

Commit

Permalink
UI test cleanup: Extract unnecessary_operation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Oct 28, 2018
1 parent 14d2700 commit 7adc8dc
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 153 deletions.
31 changes: 1 addition & 30 deletions tests/ui/no_effect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#![feature(box_syntax)]


#![warn(clippy::no_effect, clippy::unnecessary_operation)]
#![warn(clippy::no_effect)]
#![allow(dead_code)]
#![allow(path_statements)]
#![allow(clippy::deref_addrof)]
Expand Down Expand Up @@ -105,33 +105,4 @@ fn main() {
DropTuple(0);
DropEnum::Tuple(0);
DropEnum::Struct { field: 0 };

Tuple(get_number());
Struct { field: get_number() };
Struct { ..get_struct() };
Enum::Tuple(get_number());
Enum::Struct { field: get_number() };
5 + get_number();
*&get_number();
&get_number();
(5, 6, get_number());
box get_number();
get_number()..;
..get_number();
5..get_number();
[42, get_number()];
[42, 55][get_number() as usize];
(42, get_number()).1;
[get_number(); 55];
[42; 55][get_number() as usize];
{get_number()};
FooString { s: 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() };
}
124 changes: 1 addition & 123 deletions tests/ui/no_effect.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -150,127 +150,5 @@ error: statement with no effect
98 | FooString { s: s };
| ^^^^^^^^^^^^^^^^^^^

error: statement can be reduced
--> $DIR/no_effect.rs:109:5
|
109 | Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
|
= note: `-D clippy::unnecessary-operation` implied by `-D warnings`

error: statement can be reduced
--> $DIR/no_effect.rs:110:5
|
110 | Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:111:5
|
111 | Struct { ..get_struct() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_struct();`

error: statement can be reduced
--> $DIR/no_effect.rs:112:5
|
112 | Enum::Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:113:5
|
113 | Enum::Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:114:5
|
114 | 5 + get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:115:5
|
115 | *&get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:116:5
|
116 | &get_number();
| ^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:117:5
|
117 | (5, 6, get_number());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `5;6;get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:118:5
|
118 | box get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:119:5
|
119 | get_number()..;
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:120:5
|
120 | ..get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:121:5
|
121 | 5..get_number();
| ^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:122:5
|
122 | [42, get_number()];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:123:5
|
123 | [42, 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_number() as usize;`

error: statement can be reduced
--> $DIR/no_effect.rs:124:5
|
124 | (42, get_number()).1;
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:125:5
|
125 | [get_number(); 55];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:126:5
|
126 | [42; 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_number() as usize;`

error: statement can be reduced
--> $DIR/no_effect.rs:127:5
|
127 | {get_number()};
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/no_effect.rs:128:5
|
128 | FooString { s: String::from("blah"), };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");`

error: aborting due to 45 previous errors
error: aborting due to 25 previous errors

76 changes: 76 additions & 0 deletions tests/ui/unnecessary_operation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(box_syntax)]
#![allow(clippy::deref_addrof)]
#![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_struct() -> Struct { Struct { field: 0 } }
fn get_drop_struct() -> DropStruct { DropStruct { field: 0 } }

fn main() {
Tuple(get_number());
Struct { field: get_number() };
Struct { ..get_struct() };
Enum::Tuple(get_number());
Enum::Struct { field: get_number() };
5 + get_number();
*&get_number();
&get_number();
(5, 6, get_number());
box get_number();
get_number()..;
..get_number();
5..get_number();
[42, get_number()];
[42, 55][get_number() as usize];
(42, get_number()).1;
[get_number(); 55];
[42; 55][get_number() as usize];
{get_number()};
FooString { s: 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() };
}
124 changes: 124 additions & 0 deletions tests/ui/unnecessary_operation.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
error: statement can be reduced
--> $DIR/unnecessary_operation.rs:48:5
|
48 | Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`
|
= note: `-D clippy::unnecessary-operation` implied by `-D warnings`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:49:5
|
49 | Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:50:5
|
50 | Struct { ..get_struct() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_struct();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:51:5
|
51 | Enum::Tuple(get_number());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:52:5
|
52 | Enum::Struct { field: get_number() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:53:5
|
53 | 5 + get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:54:5
|
54 | *&get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:55:5
|
55 | &get_number();
| ^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:56:5
|
56 | (5, 6, get_number());
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `5;6;get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:57:5
|
57 | box get_number();
| ^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:58:5
|
58 | get_number()..;
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:59:5
|
59 | ..get_number();
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:60:5
|
60 | 5..get_number();
| ^^^^^^^^^^^^^^^^ help: replace it with: `5;get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:61:5
|
61 | [42, get_number()];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:62:5
|
62 | [42, 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42, 55];get_number() as usize;`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:63:5
|
63 | (42, get_number()).1;
| ^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `42;get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:64:5
|
64 | [get_number(); 55];
| ^^^^^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:65:5
|
65 | [42; 55][get_number() as usize];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `[42; 55];get_number() as usize;`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:66:5
|
66 | {get_number()};
| ^^^^^^^^^^^^^^^ help: replace it with: `get_number();`

error: statement can be reduced
--> $DIR/unnecessary_operation.rs:67:5
|
67 | FooString { s: String::from("blah"), };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `String::from("blah");`

error: aborting due to 20 previous errors

0 comments on commit 7adc8dc

Please sign in to comment.