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 trait PartialOrd, I simply used an option wrapper for the return of cmp 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
#![deny(clippy::implicit_return)]
#![allow(clippy::needless_return)]
use std::cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd};
pub struct Example {
data: i32,
}
impl PartialEq for Example {
fn eq(&self, other: &Self) -> bool {
return self.data == other.data;
}
}
impl Eq for Example {}
impl Ord for Example {
fn cmp(&self, other: &Self) -> Ordering {
return self.data.cmp(&other.data);
}
}
impl PartialOrd for Example {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
return Some(self.cmp(other));
}
}
I saw this happen:
Checking playground v0.0.1 (/playground)
warning: non-canonical implementation of `partial_cmp` on an `Ord` type
--> src/lib.rs:25:1
|
25 | / impl PartialOrd for Example {
26 | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
| | _____________________________________________________________-
27 | || return Some(self.cmp(other));
28 | || }
| ||_____- help: change this to: `{ Some(self.cmp(other)) }`
29 | | }
| |__^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_canonical_partial_ord_impl
= note: `#[warn(clippy::non_canonical_partial_ord_impl)]` on by default
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.36s
I expected to see this happen:
No warnings to be emitted
Version
rustc 1.76.0 (07dca489a 2024-02-04)
binary: rustc
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce
commit-date: 2024-02-04
host: x86_64-pc-windows-msvc
release: 1.76.0
LLVM version: 17.0.6
Additional Labels
No response
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 ofcmpthat 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_impllint.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