Description
Following the assigning_clones lint makes code less readable.
There is a strong semantic hint in the = operator. It gives a visual indication that a value is being assigned to.
The clone_from() function does not have this visual hint. Using clone_from() makes code harder to read and as a consequence, harder to maintain.
Consider the two snippets:
self.foo = some_value.clone()
self.foo.clone_from(some_value);
The second snippet is much less clear. In isolation this may not seem like much, but in a real codebase this is bad.
Lints should not favor performance at the cost of maintainability. Especially considering that #[derive(Clone)] doesn't even implement clone_from() and the default clone_from() is implemented as *self = source.clone(): https://github.com/rust-lang/rust/blob/5ce96b1d0f6b5093955e7b6a70dfd877395c1d73/library/core/src/clone.rs#L169-L171
I suggest the lint is changed to be turned off by default.
Version
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2
Additional Labels
No response
Description
Following the
assigning_cloneslint makes code less readable.There is a strong semantic hint in the
=operator. It gives a visual indication that a value is being assigned to.The
clone_from()function does not have this visual hint. Usingclone_from()makes code harder to read and as a consequence, harder to maintain.Consider the two snippets:
The second snippet is much less clear. In isolation this may not seem like much, but in a real codebase this is bad.
Lints should not favor performance at the cost of maintainability. Especially considering that
#[derive(Clone)]doesn't even implementclone_from()and the defaultclone_from()is implemented as*self = source.clone(): https://github.com/rust-lang/rust/blob/5ce96b1d0f6b5093955e7b6a70dfd877395c1d73/library/core/src/clone.rs#L169-L171I suggest the lint is changed to be turned off by default.
Version
Additional Labels
No response