mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
test: add more test cases
This commit is contained in:
parent
b5a2192628
commit
03b3a16a8c
3 changed files with 36 additions and 22 deletions
|
@ -181,9 +181,6 @@ fn string_retain() {
|
|||
// Do lint.
|
||||
s.retain(|c| c != 'o');
|
||||
|
||||
// Do not lint, because we need to rewrite the lambda
|
||||
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
|
||||
|
||||
// Do not lint, because this expression is not assign.
|
||||
let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect();
|
||||
|
||||
|
@ -289,6 +286,16 @@ fn issue_10393() {
|
|||
tuples.retain(|(_, n)| *n > 0);
|
||||
}
|
||||
|
||||
fn issue_11457() {
|
||||
// Do not lint, as we need to modify the closure
|
||||
let mut vals = vec![1, 2, 3, 4];
|
||||
vals = vals.iter().filter(|v| **v != 1).cloned().collect();
|
||||
|
||||
// Do not lint, as we need to modify the closure
|
||||
let mut s = String::from("foobar");
|
||||
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
|
||||
}
|
||||
|
||||
fn issue_12081() {
|
||||
let mut vec = vec![0, 1, 2];
|
||||
|
||||
|
|
|
@ -187,9 +187,6 @@ fn string_retain() {
|
|||
// Do lint.
|
||||
s = s.chars().filter(|&c| c != 'o').to_owned().collect();
|
||||
|
||||
// Do not lint, because we need to rewrite the lambda
|
||||
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
|
||||
|
||||
// Do not lint, because this expression is not assign.
|
||||
let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect();
|
||||
|
||||
|
@ -295,6 +292,16 @@ fn issue_10393() {
|
|||
tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect();
|
||||
}
|
||||
|
||||
fn issue_11457() {
|
||||
// Do not lint, as we need to modify the closure
|
||||
let mut vals = vec![1, 2, 3, 4];
|
||||
vals = vals.iter().filter(|v| **v != 1).cloned().collect();
|
||||
|
||||
// Do not lint, as we need to modify the closure
|
||||
let mut s = String::from("foobar");
|
||||
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
|
||||
}
|
||||
|
||||
fn issue_12081() {
|
||||
let mut vec = vec![0, 1, 2];
|
||||
|
||||
|
|
|
@ -140,97 +140,97 @@ LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect();
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:203:5
|
||||
--> $DIR/manual_retain.rs:200:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:204:5
|
||||
--> $DIR/manual_retain.rs:201:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:205:5
|
||||
--> $DIR/manual_retain.rs:202:5
|
||||
|
|
||||
LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:209:5
|
||||
--> $DIR/manual_retain.rs:206:5
|
||||
|
|
||||
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:210:5
|
||||
--> $DIR/manual_retain.rs:207:5
|
||||
|
|
||||
LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:232:5
|
||||
--> $DIR/manual_retain.rs:229:5
|
||||
|
|
||||
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:233:5
|
||||
--> $DIR/manual_retain.rs:230:5
|
||||
|
|
||||
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:234:5
|
||||
--> $DIR/manual_retain.rs:231:5
|
||||
|
|
||||
LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:291:5
|
||||
--> $DIR/manual_retain.rs:288:5
|
||||
|
|
||||
LL | vec = vec.into_iter().filter(|(x, y)| *x == 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|(x, y)| *x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:295:5
|
||||
--> $DIR/manual_retain.rs:292:5
|
||||
|
|
||||
LL | tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(_, n)| *n > 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:302:5
|
||||
--> $DIR/manual_retain.rs:309:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&&x| x == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:303:5
|
||||
--> $DIR/manual_retain.rs:310:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&&x| x == 0).cloned().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:304:5
|
||||
--> $DIR/manual_retain.rs:311:5
|
||||
|
|
||||
LL | vec = vec.into_iter().filter(|&x| x == 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:307:5
|
||||
--> $DIR/manual_retain.rs:314:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&x| *x == 0).copied().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:308:5
|
||||
--> $DIR/manual_retain.rs:315:5
|
||||
|
|
||||
LL | vec = vec.iter().filter(|&x| *x == 0).cloned().collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`
|
||||
|
||||
error: this expression can be written more simply using `.retain()`
|
||||
--> $DIR/manual_retain.rs:309:5
|
||||
--> $DIR/manual_retain.rs:316:5
|
||||
|
|
||||
LL | vec = vec.into_iter().filter(|x| *x == 0).collect();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`
|
||||
|
|
Loading…
Reference in a new issue