Closed siddiqua1 closed 2 weeks ago
After a brief look at the source code it seems the same is applicable to the lint non_canonical_clone_impl
Code:
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]
use std::cmp::{Eq, PartialEq};
#[derive(Eq, PartialEq)]
struct A(u32);
impl Clone for A {
fn clone(&self) -> Self {
return *self;
}
}
impl Copy for A {}
Warnings:
Checking playground v0.0.1 (/playground)
warning: non-canonical implementation of `clone` on a `Copy` type
--> src/lib.rs:10:29
|
10 | fn clone(&self) -> Self {
| _____________________________^
11 | | return *self;
12 | | }
| |_____^ 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: `#[warn(clippy::non_canonical_clone_impl)]` on by default
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.33s
Summary
For my code bases, I prefer to have
#![deny(clippy::implicit_return)]
and#![allow(clippy::needless_return)]
. When I implemented a custom type to have traitPartialOrd
, I simply used an option wrapper for the return ofcmp
that is user defined. It seems this implementation conflicts with the default#[warn(clippy::non_canonical_partial_ord_impl)]
.While I can disable this lint, I imagine the intended behavior from the user's perspective would be to implicitly disable the
non_canonical_partial_ord_impl
lint.Lint Name
non_canonical_partial_ord_impl
Reproducer
I tried this code: Rust Playground
I saw this happen:
I expected to see this happen:
No warnings to be emitted
Version
Additional Labels
No response