diff options
| author | Ryan1729 <Ryan1729@gmail.com> | 2020-07-26 21:36:50 -0600 |
|---|---|---|
| committer | Ryan1729 <Ryan1729@gmail.com> | 2020-07-26 21:36:50 -0600 |
| commit | 0722991b62fd6e4d7d7a51425274f3288bcc96bc (patch) | |
| tree | e034b64c6ea3968ff1cf2fbe38af055793c47dcd | |
| parent | fc20ee63a105c0df78113126e8749f5958d7dc47 (diff) | |
| download | rust-0722991b62fd6e4d7d7a51425274f3288bcc96bc.tar.gz rust-0722991b62fd6e4d7d7a51425274f3288bcc96bc.zip | |
add test for derive_ord_xor_partial_ord based on test for derive_hash_xor_partial_eq
| -rw-r--r-- | tests/ui/derive_ord_xor_partial_ord.rs | 67 | ||||
| -rw-r--r-- | tests/ui/derive_ord_xor_partial_ord.stderr | 1 |
2 files changed, 66 insertions, 2 deletions
diff --git a/tests/ui/derive_ord_xor_partial_ord.rs b/tests/ui/derive_ord_xor_partial_ord.rs index 63687e7b3db..15f66b7a9c5 100644 --- a/tests/ui/derive_ord_xor_partial_ord.rs +++ b/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() {} \ No newline at end of file diff --git a/tests/ui/derive_ord_xor_partial_ord.stderr b/tests/ui/derive_ord_xor_partial_ord.stderr new file mode 100644 index 00000000000..30404ce4c54 --- /dev/null +++ b/tests/ui/derive_ord_xor_partial_ord.stderr @@ -0,0 +1 @@ +TODO \ No newline at end of file |
