Why `clippy` report a unconditional recursion here?

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

I've copied your code to the playground - no warnings from Clippy, as expected. Could you share the code which actually triggers a warning?

I upgraded the rustc (with rustup update), and the warning disappeared!
Thanks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.