Skip to content

Commit 856aa03

Browse files
committed
Add Iterator::map to useless_conversion
1 parent 06df913 commit 856aa03

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,8 @@ fn has_eligible_receiver(cx: &LateContext<'_>, recv: &Expr<'_>, expr: &Expr<'_>)
434434
return true;
435435
}
436436
}
437+
if is_trait_method(cx, expr, sym::Iterator) {
438+
return true;
439+
}
437440
false
438441
}

tests/ui/useless_conversion.fixed

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,17 @@ fn direct_application() {
328328
Self
329329
}
330330
}
331+
let _: Vec<u32> = [1u32].into_iter().collect();
332+
//~^ useless_conversion
331333

332334
// No lint for those
333335
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(Into::into);
334336
let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into);
335337
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(From::from);
336338
let _: Result<(), Absorb> = test_issue_3913().map_err(From::from);
337-
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
339+
}
340+
341+
fn gen_identity<T>(x: [T; 3]) -> Vec<T> {
342+
x.into_iter().collect()
343+
//~^ useless_conversion
338344
}

tests/ui/useless_conversion.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,17 @@ fn direct_application() {
328328
Self
329329
}
330330
}
331+
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
332+
//~^ useless_conversion
331333

332334
// No lint for those
333335
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(Into::into);
334336
let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into);
335337
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(From::from);
336338
let _: Result<(), Absorb> = test_issue_3913().map_err(From::from);
337-
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
339+
}
340+
341+
fn gen_identity<T>(x: [T; 3]) -> Vec<T> {
342+
x.into_iter().map(Into::into).collect()
343+
//~^ useless_conversion
338344
}

tests/ui/useless_conversion.stderr

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,17 @@ error: useless conversion to the same type: `()`
262262
LL | let _: ControlFlow<()> = c.map_continue(Into::into);
263263
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing
264264

265-
error: aborting due to 34 previous errors
265+
error: useless conversion to the same type: `u32`
266+
--> tests/ui/useless_conversion.rs:331:41
267+
|
268+
LL | let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
269+
| ^^^^^^^^^^^^^^^^ help: consider removing
270+
271+
error: useless conversion to the same type: `T`
272+
--> tests/ui/useless_conversion.rs:342:18
273+
|
274+
LL | x.into_iter().map(Into::into).collect()
275+
| ^^^^^^^^^^^^^^^^ help: consider removing
276+
277+
error: aborting due to 36 previous errors
266278

0 commit comments

Comments
 (0)