Skip to content

incorrect_clone_impl_on_copy_type false positive on empty enum #11071

Open
@dtolnay

Description

@dtolnay

Summary

Would you be willing to consider the exact expression match *self {} a correct Clone impl for a Copy type?

This immediately conveys "don't even bother" in a way that *self does not.

Lint Name

incorrect_clone_impl_on_copy_type

Reproducer

enum Void {}

impl Copy for Void {}

impl Clone for Void {
    fn clone(&self) -> Self {
        match *self {}
    }
}
error: incorrect implementation of `clone` on a `Copy` type
 --> src/main.rs:6:29
  |
6 |       fn clone(&self) -> Self {
  |  _____________________________^
7 | |         match *self {}
8 | |     }
  | |_____^ help: change this to: `{ *self }`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incorrect_clone_impl_on_copy_type
  = note: `#[deny(clippy::incorrect_clone_impl_on_copy_type)]` on by default

Version

rustc 1.72.0-nightly (839e9a6e1 2023-07-02)
binary: rustc
commit-hash: 839e9a6e1210934fd24b15548b811a97c77138fc
commit-date: 2023-07-02
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions