Open
Description
$ rustc --version
rustc 1.83.0-nightly (363ae4188 2024-09-24)
use std::cmp::Ordering;
use compare::Compare;
use num_cmp::NumCmp;
trait PartialCompare<L: ?Sized, R: ?Sized = L> {
fn compare(&self, l: &L, r: &R) -> Option<Ordering>;
}
impl<L, R, C: Compare<L, R>> PartialCompare<L, R> for C {
fn compare(&self, l: &L, r: &R) -> Option<Ordering> {
Some(self.compare(l, r))
}
}
#[derive(Default, Debug, Clone, Copy)]
struct NumCompare;
impl<L, R> PartialCompare<L, R> for NumCompare
where
L: NumCmp<R> + Copy,
R: Copy,
{
fn compare(&self, l: &L, r: &R) -> Option<Ordering> {
NumCmp::num_cmp(*l, *r)
}
}
fn main() {}
With dependencies:
num-cmp = "0.1.0"
compare = "0.1.0"
Failed to compile:
error[E0119]: conflicting implementations of trait `PartialCompare<_, _>` for type `NumCompare`
--> src/main.rs:18:1
|
9 | impl<L, R, C: Compare<L, R>> PartialCompare<L, R> for C {
| ------------------------------------------------------- first implementation here
...
18 | / impl<L, R> PartialCompare<L, R> for NumCompare
19 | | where
20 | | L: NumCmp<R> + Copy,
21 | | R: Copy,
| |____________^ conflicting implementation for `NumCompare`
|
= note: downstream crates may implement trait `compare::Compare<_, _>` for type `NumCompare`
Since both PartialCompare
and NumCompare
are defined in this crate, the error message seems incorrect. Not sure it's a bug or an error messaging inaccurate.