This commit is contained in:
Catherine 2023-06-30 15:16:56 -05:00
parent 844afbfeba
commit a5dfb68491
5 changed files with 174 additions and 50 deletions

View file

@ -16,7 +16,7 @@ LL | / fn clone_from(&mut self, source: &Self) {
LL | | source.clone();
LL | | *self = source.clone();
LL | | }
| |_____^ help: remove this
| |_____^ help: remove it
error: incorrect implementation of `clone` on a `Copy` type
--> $DIR/incorrect_clone_impl_on_copy_type.rs:81:29
@ -34,7 +34,7 @@ LL | / fn clone_from(&mut self, source: &Self) {
LL | | source.clone();
LL | | *self = source.clone();
LL | | }
| |_____^ help: remove this
| |_____^ help: remove it
error: aborting due to 4 previous errors

View file

@ -0,0 +1,114 @@
//@run-rustfix
#![allow(unused)]
#![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> { Some(self.cmp(other)) }
}
// 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, and give `_` a name
#[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, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
}
// do not lint derived
#[derive(Eq, Ord, PartialEq, PartialOrd)]
struct D(u32);
// do not lint if ord is not manually implemented
#[derive(Eq, PartialEq)]
struct E(u32);
impl PartialOrd for E {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
// do not lint since ord has more restrictive bounds
#[derive(Eq, PartialEq)]
struct Uwu<A>(A);
impl<A: std::fmt::Debug + Ord + PartialOrd> Ord for Uwu<A> {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl<A: Ord + PartialOrd> PartialOrd for Uwu<A> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
todo!();
}
}
// do not lint since `Rhs` is not `Self`
#[derive(Eq, PartialEq)]
struct F(u32);
impl Ord for F {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for F {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq<u32> for F {
fn eq(&self, other: &u32) -> bool {
todo!();
}
}
impl PartialOrd<u32> for F {
fn partial_cmp(&self, other: &u32) -> Option<Ordering> {
todo!();
}
}

View file

@ -1,3 +1,4 @@
//@run-rustfix
#![allow(unused)]
#![no_main]
@ -37,7 +38,7 @@ impl PartialOrd for B {
}
}
// lint, but we can't give a suggestion since &Self is not named
// lint, and give `_` a name
#[derive(Eq, PartialEq)]
struct C(u32);
@ -50,7 +51,7 @@ impl Ord for C {
impl PartialOrd for C {
fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
todo!(); // don't run rustfix, or else this will cause it to fail to compile
todo!();
}
}

View file

@ -1,5 +1,5 @@
error: incorrect implementation of `partial_cmp` on an `Ord` type
--> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:17:1
--> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:18:1
|
LL | / impl PartialOrd for A {
LL | | fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
@ -13,16 +13,19 @@ LL | | }
= note: `#[deny(clippy::incorrect_partial_ord_impl_on_ord_type)]` on by default
error: incorrect implementation of `partial_cmp` on an `Ord` type
--> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:51:1
--> $DIR/incorrect_partial_ord_impl_on_ord_type.rs:52:1
|
LL | / impl PartialOrd for C {
LL | | fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
| | _________________________________________________________-
LL | || todo!(); // don't run rustfix, or else this will cause it to fail to compile
LL | || }
| ||_____- help: change this to: `{ Some(self.cmp(...)) }`
LL | | }
| |__^
LL | / impl PartialOrd for C {
LL | | fn partial_cmp(&self, _: &Self) -> Option<Ordering> {
LL | | todo!();
LL | | }
LL | | }
| |_^
|
help: change this to
|
LL | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.cmp(other)) }
| ~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors