You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's shorter to write than other options, and it always correct -- anything with different behaviour would be a violation of the Copy+Clone contract.
Thus using any other implementation is just asking for that more-complicated implementation to have a logic error.
Drawbacks
Macros might not want to special-case their generation to meet this.
Example
use std::marker::PhantomData;structId<T>(u32,PhantomData<T>);impl<T>CloneforId<T>{fnclone(&self) -> Self{Id(self.0.clone(),PhantomData)}}impl<T>CopyforId<T>{}
Could be written as:
use std::marker::PhantomData;structId<T>(u32,PhantomData<T>);impl<T>CloneforId<T>{fnclone(&self) -> Self{*self}}impl<T>CopyforId<T>{}
(Which, notably, can't just use #[derive(Copy, Clone)].)
The text was updated successfully, but these errors were encountered:
Here's an example of a place in the wild where this lint is would have been applicable: bevyengine/bevy#8247. This one is made especially nicer by dereferencing, since it allows us to skip referring to a #[cfg] field.
What it does
If a type's
Clone
impl has the samewhere
bounds as itsCopy
impl, then this gives a warning unless theClone
impl body is exactlyInspired by the incorrect code in https://users.rust-lang.org/t/why-is-the-value-expression-with-the-type-implemented-copy-not-desugared-to-e-clone/92921?u=scottmcm, which currently gets no clippy warnings https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=3fa61e0abb79c6a444d2ef77a5c6033c.
Lint Name
overcomplicated_clone_impl
Category
suspicious, complexity
Advantage
It's shorter to write than other options, and it always correct -- anything with different behaviour would be a violation of the
Copy
+Clone
contract.Thus using any other implementation is just asking for that more-complicated implementation to have a logic error.
Drawbacks
Macros might not want to special-case their generation to meet this.
Example
Could be written as:
(Which, notably, can't just use
#[derive(Copy, Clone)]
.)The text was updated successfully, but these errors were encountered: