Skip to content

Commit

Permalink
Add Iterator::map to useless_conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Dec 1, 2024
1 parent 005ff7b commit 0b867cf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 3 additions & 0 deletions clippy_lints/src/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,5 +433,8 @@ fn has_eligible_receiver(cx: &LateContext<'_>, recv: &Expr<'_>, expr: &Expr<'_>)
return true;
}
}
if is_trait_method(cx, expr, sym::Iterator) {
return true;
}
false
}
8 changes: 7 additions & 1 deletion tests/ui/useless_conversion.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,17 @@ fn direct_application() {
Self
}
}
let _: Vec<u32> = [1u32].into_iter().collect();
//~^ useless_conversion

// No lint for those
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(Into::into);
let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into);
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(From::from);
let _: Result<(), Absorb> = test_issue_3913().map_err(From::from);
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
}

fn gen_identity<T>(x: [T; 3]) -> Vec<T> {
x.into_iter().collect()
//~^ useless_conversion
}
8 changes: 7 additions & 1 deletion tests/ui/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,17 @@ fn direct_application() {
Self
}
}
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
//~^ useless_conversion

// No lint for those
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(Into::into);
let _: Result<(), Absorb> = test_issue_3913().map_err(Into::into);
let _: Result<Absorb, std::io::Error> = test_issue_3913().map(From::from);
let _: Result<(), Absorb> = test_issue_3913().map_err(From::from);
let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
}

fn gen_identity<T>(x: [T; 3]) -> Vec<T> {
x.into_iter().map(Into::into).collect()
//~^ useless_conversion
}
14 changes: 13 additions & 1 deletion tests/ui/useless_conversion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,17 @@ error: useless conversion to the same type: `()`
LL | let _: ControlFlow<()> = c.map_continue(Into::into);
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing

error: aborting due to 34 previous errors
error: useless conversion to the same type: `u32`
--> tests/ui/useless_conversion.rs:331:41
|
LL | let _: Vec<u32> = [1u32].into_iter().map(Into::into).collect();
| ^^^^^^^^^^^^^^^^ help: consider removing

error: useless conversion to the same type: `T`
--> tests/ui/useless_conversion.rs:342:18
|
LL | x.into_iter().map(Into::into).collect()
| ^^^^^^^^^^^^^^^^ help: consider removing

error: aborting due to 36 previous errors

0 comments on commit 0b867cf

Please sign in to comment.