Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn about clone impls for Copy types #107

Closed
oli-obk opened this issue Jul 2, 2015 · 2 comments
Closed

Warn about clone impls for Copy types #107

oli-obk opened this issue Jul 2, 2015 · 2 comments

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jul 2, 2015

The following is legal and totally weird/useless

#[derive(Copy)]
struct A;

impl Clone for A {
    fn clone(&self) -> A {
        panic!("bla");
    }
}

fn main() {
    let a = A;
    let b = a;
    let c = a.clone();
}
@llogiq
Copy link
Contributor

llogiq commented Jul 2, 2015

It depends. Copy is usually shallow, while clone may copy data behind pointers – it's a deep copy.

To have both may be useful in some situations. Implementing clone by accident isn't terribly common, so I doubt the value proposition of such a lint.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 2, 2015

It's rather rare, I agree.

@oli-obk oli-obk closed this as completed Jul 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants