Skip to content

Commit

Permalink
test: add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxqiu committed Jan 4, 2024
1 parent b5a2192 commit 03b3a16
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
13 changes: 10 additions & 3 deletions tests/ui/manual_retain.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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];

Expand Down
13 changes: 10 additions & 3 deletions tests/ui/manual_retain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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];

Expand Down
32 changes: 16 additions & 16 deletions tests/ui/manual_retain.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down

0 comments on commit 03b3a16

Please sign in to comment.