implement manual_partial_ord_impl

first try at this
This commit is contained in:
Centri3 2023-05-15 16:50:28 -05:00 committed by Catherine
parent 3a1fc26665
commit 2a1fd22f81
6 changed files with 220 additions and 0 deletions

View file

@ -0,0 +1,57 @@
#![allow(unused)]
#![warn(clippy::manual_partial_ord_impl)]
#![no_main]
use std::cmp::Ordering;
// lint
#[derive(Eq, PartialEq)]
struct A(u32);
impl Ord for A {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for A {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
// do not lint
#[derive(Eq, PartialEq)]
struct B(u32);
impl Ord for B {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for B {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
// lint, but we cannot give a suggestion since &Self is not named
#[derive(Eq, PartialEq)]
struct C(u32);
impl Ord for C {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for C {
fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
todo!();
}
}

View file

@ -0,0 +1,28 @@
error: manual implementation of `PartialOrd` when `Ord` is already implemented
--> $DIR/manual_partial_ord_impl.rs:18:1
|
LL | / impl PartialOrd for A {
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
| | _____________________________________________________________-
LL | || todo!();
LL | || }
| ||_____- help: change this to: `{ Some(self.cmp(other)) }`
LL | | }
| |__^
|
= note: `-D clippy::manual-partial-ord-impl` implied by `-D warnings`
error: manual implementation of `PartialOrd` when `Ord` is already implemented
--> $DIR/manual_partial_ord_impl.rs:52:1
|
LL | / impl PartialOrd for C {
LL | | fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
LL | | todo!();
LL | | }
LL | | }
| |_^
|
= help: return the value of `self.cmp` wrapped in `Some` instead
error: aborting due to 2 previous errors