Considering this code:
let s = format!("Hello, {}", "world").to_string();
This to_string() isn't needed because format! returns String type.
It'd be nice for Clippy to tell us it's needless.
redundant_clone contains general check for calling to_string() on String (just because it can be seen as cloning). It might better be extracted into another lint.
Yes, what @sinkuu said, this is already linted:
#[warn(clippy::redundant_clone)]
fn main() {
let _s = format!("Hello, {}", "world").to_string();
}
But the redundant_clone lint is in the nursery group, because https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
So yeah maybe this could be extracted in a more restricted lint, that can be warn-by-default.
E-medium if someone wants to attempt to fix this lint in itself.
Hey. Can I take this?
@Shubhamchinda go ahead!
Most helpful comment
redundant_clonecontains general check for callingto_string()onString(just because it can be seen as cloning). It might better be extracted into another lint.https://github.com/rust-lang/rust-clippy/blob/4c8a941dafff56a2485258b85b33ba33e66f6258/tests/ui/redundant_clone.stderr#L1-L12