forked from rust-lang/rust-clippy
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for derive_ord_xor_partial_ord based on test for derive_hash…
…_xor_partial_eq
- Loading branch information
Showing
2 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,68 @@ | ||
#![warn(clippy::derive_ord_xor_partial_ord)] | ||
|
||
fn main() { | ||
// test code goes here | ||
use std::cmp::Ordering; | ||
|
||
#[derive(PartialOrd, Ord, PartialEq, Eq)] | ||
struct DeriveBoth; | ||
|
||
impl PartialEq<u64> for DeriveBoth { | ||
fn eq(&self, _: &u64) -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl PartialOrd<u64> for DeriveBoth { | ||
fn partial_cmp(&self, _: &u64) -> Option<Ordering> { | ||
Some(Ordering::Equal) | ||
} | ||
} | ||
|
||
#[derive(Ord, PartialEq, Eq)] | ||
struct DeriveOrd; | ||
|
||
impl PartialOrd for DeriveOrd { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(other.cmp(self)) | ||
} | ||
} | ||
|
||
#[derive(Ord, PartialEq, Eq)] | ||
struct DeriveOrdWithExplicitTypeVariable; | ||
|
||
impl PartialOrd<DeriveOrdWithExplicitTypeVariable> for DeriveOrdWithExplicitTypeVariable { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(other.cmp(self)) | ||
} | ||
} | ||
|
||
#[derive(PartialOrd, PartialEq, Eq)] | ||
struct DerivePartialOrd; | ||
|
||
impl std::cmp::Ord for DerivePartialOrd { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
Ordering::Less | ||
} | ||
} | ||
|
||
#[derive(PartialOrd, PartialEq, Eq)] | ||
struct ImplUserOrd; | ||
|
||
trait Ord {} | ||
|
||
// We don't want to lint on user-defined traits called `Ord` | ||
impl Ord for ImplUserOrd {} | ||
|
||
mod use_ord { | ||
use std::cmp::{Ord, Ordering}; | ||
|
||
#[derive(PartialOrd, PartialEq, Eq)] | ||
struct DerivePartialOrdInUseOrd; | ||
|
||
impl Ord for DerivePartialOrdInUseOrd { | ||
fn cmp(&self, other: &Self) -> Ordering { | ||
Ordering::Less | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
TODO |