Skip to content

Commit

Permalink
add test for derive_ord_xor_partial_ord based on test for derive_hash…
Browse files Browse the repository at this point in the history
…_xor_partial_eq
  • Loading branch information
Ryan1729 committed Jul 27, 2020
1 parent fc20ee6 commit 0722991
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
67 changes: 65 additions & 2 deletions tests/ui/derive_ord_xor_partial_ord.rs
@@ -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() {}
1 change: 1 addition & 0 deletions tests/ui/derive_ord_xor_partial_ord.stderr
@@ -0,0 +1 @@
TODO

0 comments on commit 0722991

Please sign in to comment.