Skip to content

Denying non_canonical_clone_impl and implicit_return is incompatible #16945

@ElementW

Description

@ElementW

Summary

Implicit returns are evil in my book and the non_canonical_*_impl are good to have, but this is a repeat of #12683 because #12702 only fixed the ordering half of those, not the clone half.

Lint Name

non_canonical_clone_impl

Reproducer

I tried this code:

#![deny(clippy::non_canonical_clone_impl)]
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]

pub struct Container<T: Copy> {
    pub value: T,
}

impl<T: Copy> Copy for Container<T> {}

impl<T: Copy> Clone for Container<T> {
    fn clone(&self) -> Self {
        return *self;
    }
}

I saw this happen:

error: non-canonical implementation of `clone` on a `Copy` type
  --> src/main.rs:12:29
   |
12 |       fn clone(&self) -> Self {
   |  _____________________________^
13 | |         return *self;
14 | |     }
   | |_____^ help: change this to: `{ *self }`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_canonical_clone_impl
note: the lint level is defined here
  --> src/main.rs:1:9
   |
 1 | #![deny(clippy::non_canonical_clone_impl)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If Clippy's suggestion is applied, the following happens instead:

error: missing `return` statement
  --> src/main.rs:13:9
   |
13 |         *self
   |         ^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
note: the lint level is defined here
  --> src/main.rs:2:9
   |
 2 | #![deny(clippy::implicit_return)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^
help: add `return` as shown
   |
13 |         return *self
   |         ++++++

The suggestion there just sends you back to square one.

I expected to see this happen:

Lint passes, and non_canonical_clone_impl

implicit_return allowed implicit_return denied
needless_return allowed allows both requires return *self;
needless_return denied requires *self implodes?

Version

rustc 1.97.0-nightly (37d85e592 2026-04-28)
binary: rustc
commit-hash: 37d85e592f9ae5f20f7d9a9f99785246fa7298da
commit-date: 2026-04-28
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4

Additional Labels

No response

Metadata

Metadata

Assignees

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
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions