I have a struct
, and plan to perform the eq
comparison only based on some of its member(s). The clippy
reported an warning that I do not understand.
Here is the minimum reproducible code:
pub struct IdxDistPair<T>
where
T: PartialOrd,
{
pub index: usize,
pub dist: T,
}
//I need to use the member `dist` to perform the comparison, and ignore `index.`
impl<T> PartialEq for IdxDistPair<T>
where
T: PartialOrd,
{
fn eq(&self, other: &Self) -> bool {
self.dist.eq(&(other.dist)) //<- clippy report I have an unconditional recursion here, which I don't think is.
}
}
fn main(){}
Then I run the cargo clippy
here and get following outputs:
Checking clippy_test v0.1.0 (/home/astrojhgu/temp/clippy_test)
warning: function cannot return without recursing
--> src/main.rs:13:5
|
13 | / fn eq(&self, other: &Self) -> bool {
14 | | self.dist.eq(&(other.dist))
15 | | }
| |_____^
|
note: recursive call site
--> src/main.rs:14:9
|
14 | self.dist.eq(&(other.dist))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
= note: `#[warn(clippy::unconditional_recursion)]` on by default
warning: `clippy_test` (bin "clippy_test") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.07s