Skip to content

Commit 03b3a16

Browse files
committed
test: add more test cases
1 parent b5a2192 commit 03b3a16

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

tests/ui/manual_retain.fixed

+10-3
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ fn string_retain() {
181181
// Do lint.
182182
s.retain(|c| c != 'o');
183183

184-
// Do not lint, because we need to rewrite the lambda
185-
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
186-
187184
// Do not lint, because this expression is not assign.
188185
let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect();
189186

@@ -289,6 +286,16 @@ fn issue_10393() {
289286
tuples.retain(|(_, n)| *n > 0);
290287
}
291288

289+
fn issue_11457() {
290+
// Do not lint, as we need to modify the closure
291+
let mut vals = vec![1, 2, 3, 4];
292+
vals = vals.iter().filter(|v| **v != 1).cloned().collect();
293+
294+
// Do not lint, as we need to modify the closure
295+
let mut s = String::from("foobar");
296+
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
297+
}
298+
292299
fn issue_12081() {
293300
let mut vec = vec![0, 1, 2];
294301

tests/ui/manual_retain.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ fn string_retain() {
187187
// Do lint.
188188
s = s.chars().filter(|&c| c != 'o').to_owned().collect();
189189

190-
// Do not lint, because we need to rewrite the lambda
191-
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
192-
193190
// Do not lint, because this expression is not assign.
194191
let mut bar: String = s.chars().filter(|&c| c != 'o').to_owned().collect();
195192

@@ -295,6 +292,16 @@ fn issue_10393() {
295292
tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect();
296293
}
297294

295+
fn issue_11457() {
296+
// Do not lint, as we need to modify the closure
297+
let mut vals = vec![1, 2, 3, 4];
298+
vals = vals.iter().filter(|v| **v != 1).cloned().collect();
299+
300+
// Do not lint, as we need to modify the closure
301+
let mut s = String::from("foobar");
302+
s = s.chars().filter(|c| *c != 'o').to_owned().collect();
303+
}
304+
298305
fn issue_12081() {
299306
let mut vec = vec![0, 1, 2];
300307

tests/ui/manual_retain.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -140,97 +140,97 @@ LL | s = s.chars().filter(|&c| c != 'o').to_owned().collect();
140140
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `s.retain(|c| c != 'o')`
141141

142142
error: this expression can be written more simply using `.retain()`
143-
--> $DIR/manual_retain.rs:203:5
143+
--> $DIR/manual_retain.rs:200:5
144144
|
145145
LL | vec = vec.iter().filter(|&x| x % 2 == 0).copied().collect();
146146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
147147

148148
error: this expression can be written more simply using `.retain()`
149-
--> $DIR/manual_retain.rs:204:5
149+
--> $DIR/manual_retain.rs:201:5
150150
|
151151
LL | vec = vec.iter().filter(|&x| x % 2 == 0).cloned().collect();
152152
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
153153

154154
error: this expression can be written more simply using `.retain()`
155-
--> $DIR/manual_retain.rs:205:5
155+
--> $DIR/manual_retain.rs:202:5
156156
|
157157
LL | vec = vec.into_iter().filter(|x| x % 2 == 0).collect();
158158
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| x % 2 == 0)`
159159

160160
error: this expression can be written more simply using `.retain()`
161-
--> $DIR/manual_retain.rs:209:5
161+
--> $DIR/manual_retain.rs:206:5
162162
|
163163
LL | tuples = tuples.iter().filter(|(ref x, ref y)| *x == 0).copied().collect();
164164
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(ref x, ref y)| *x == 0)`
165165

166166
error: this expression can be written more simply using `.retain()`
167-
--> $DIR/manual_retain.rs:210:5
167+
--> $DIR/manual_retain.rs:207:5
168168
|
169169
LL | tuples = tuples.iter().filter(|(x, y)| *x == 0).copied().collect();
170170
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(x, y)| *x == 0)`
171171

172172
error: this expression can be written more simply using `.retain()`
173-
--> $DIR/manual_retain.rs:232:5
173+
--> $DIR/manual_retain.rs:229:5
174174
|
175175
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).copied().collect();
176176
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
177177

178178
error: this expression can be written more simply using `.retain()`
179-
--> $DIR/manual_retain.rs:233:5
179+
--> $DIR/manual_retain.rs:230:5
180180
|
181181
LL | vec_deque = vec_deque.iter().filter(|&x| x % 2 == 0).cloned().collect();
182182
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
183183

184184
error: this expression can be written more simply using `.retain()`
185-
--> $DIR/manual_retain.rs:234:5
185+
--> $DIR/manual_retain.rs:231:5
186186
|
187187
LL | vec_deque = vec_deque.into_iter().filter(|x| x % 2 == 0).collect();
188188
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec_deque.retain(|x| x % 2 == 0)`
189189

190190
error: this expression can be written more simply using `.retain()`
191-
--> $DIR/manual_retain.rs:291:5
191+
--> $DIR/manual_retain.rs:288:5
192192
|
193193
LL | vec = vec.into_iter().filter(|(x, y)| *x == 0).collect();
194194
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|(x, y)| *x == 0)`
195195

196196
error: this expression can be written more simply using `.retain()`
197-
--> $DIR/manual_retain.rs:295:5
197+
--> $DIR/manual_retain.rs:292:5
198198
|
199199
LL | tuples = tuples.into_iter().filter(|(_, n)| *n > 0).collect();
200200
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `tuples.retain(|(_, n)| *n > 0)`
201201

202202
error: this expression can be written more simply using `.retain()`
203-
--> $DIR/manual_retain.rs:302:5
203+
--> $DIR/manual_retain.rs:309:5
204204
|
205205
LL | vec = vec.iter().filter(|&&x| x == 0).copied().collect();
206206
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
207207

208208
error: this expression can be written more simply using `.retain()`
209-
--> $DIR/manual_retain.rs:303:5
209+
--> $DIR/manual_retain.rs:310:5
210210
|
211211
LL | vec = vec.iter().filter(|&&x| x == 0).cloned().collect();
212212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
213213

214214
error: this expression can be written more simply using `.retain()`
215-
--> $DIR/manual_retain.rs:304:5
215+
--> $DIR/manual_retain.rs:311:5
216216
|
217217
LL | vec = vec.into_iter().filter(|&x| x == 0).collect();
218218
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|&x| x == 0)`
219219

220220
error: this expression can be written more simply using `.retain()`
221-
--> $DIR/manual_retain.rs:307:5
221+
--> $DIR/manual_retain.rs:314:5
222222
|
223223
LL | vec = vec.iter().filter(|&x| *x == 0).copied().collect();
224224
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`
225225

226226
error: this expression can be written more simply using `.retain()`
227-
--> $DIR/manual_retain.rs:308:5
227+
--> $DIR/manual_retain.rs:315:5
228228
|
229229
LL | vec = vec.iter().filter(|&x| *x == 0).cloned().collect();
230230
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`
231231

232232
error: this expression can be written more simply using `.retain()`
233-
--> $DIR/manual_retain.rs:309:5
233+
--> $DIR/manual_retain.rs:316:5
234234
|
235235
LL | vec = vec.into_iter().filter(|x| *x == 0).collect();
236236
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling `.retain()` instead: `vec.retain(|x| *x == 0)`

0 commit comments

Comments
 (0)