rust-lang / rust-lang/rust-clippy

incorrect_clone_impl_on_copy_type false positive on empty enum

Open
#11,071 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the incorrect_clone_impl_on_copy_type lint and the Rust reproducer in src/main.rs; inspect how the empty-enum match expression is classified. Done means this valid Clone implementation is no longer reported as incorrect, with regression coverage for the reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.