Closed
Description
The new Clippy in 1.34 makes a suggestion that doesn't work:
use std::ops::Deref;
struct Foo;
impl Deref for Foo {
type Target = str;
fn deref(&self) -> &str {
"hi"
}
}
fn main() {
let _ = [Foo].iter().map(|s| s.to_string()).collect::<Vec<_>>();;
}
warning: redundant closure found
--> src/main.rs:14:30
|
14 | let _ = [Foo].iter().map(|s| s.to_string()).collect::<Vec<_>>();
| ^^^^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::ToString::to_string`
|
= note: #[warn(clippy::redundant_closure)] on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure
You can't remove the closure since ToString::to_string
won't deref the Foo to a &str.