implement manual_partial_ord_impl
first try at this
This commit is contained in:
parent
3a1fc26665
commit
2a1fd22f81
6 changed files with 220 additions and 0 deletions
57
tests/ui/manual_partial_ord_impl.rs
Normal file
57
tests/ui/manual_partial_ord_impl.rs
Normal 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!();
|
||||
}
|
||||
}
|
||||
|
||||
28
tests/ui/manual_partial_ord_impl.stderr
Normal file
28
tests/ui/manual_partial_ord_impl.stderr
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue