#False positive clippy lint about recurison?

10 messages · Page 1 of 1 (latest)

rose pasture
#

beta version of clippy generates warning to the following code:

fn main() {
    let a = TypeA;
    let b = TypeA;
    println!("Is the two values the same? {}", PartialEq::eq(&a, &b));
    println!("Successfullt returned without infinite recursion")
}

#[derive(Debug)]
pub struct TypeA;
impl TypeA {
    pub fn as_bytes(&self) -> &[u8; 16] {
        &[0; 16]
    }
}

impl PartialEq for TypeA {
    fn eq(&self, other: &Self) -> bool {
        println!("Asserting...");
        self.as_bytes().eq(other.as_bytes())
    }
}

which leads to

PS D:\GitHubProjects\playground> cargo clippy
    Checking playground v0.1.0 (D:\GitHubProjects\playground)
warning: function cannot return without recursing
  --> src\main.rs:17:5
   |
17 | /     fn eq(&self, other: &Self) -> bool {
18 | |         println!("Asserting...");
19 | |         self.as_bytes().eq(other.as_bytes())
20 | |     }
   | |_____^
   |
note: recursive call site
  --> src\main.rs:19:9
   |
19 |         self.as_bytes().eq(other.as_bytes())
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = 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: `playground` (bin "playground") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.11s

Is this a false positive or a real problem? No such warning for stable rustc 1.76.0 (07dca489a 2024-02-04) or nightly rustc 1.78.0-nightly (ee9c7c940 2024-02-14) or 1.78.0-nightly (a165f1f65 2024-03-12), happens when using rustc 1.77.0-beta.7 (339fb6965 2024-03-06).
related: https://github.com/libp2p/rust-libp2p/actions/runs/7752369539/job/21141748183 (no error, with 1.76.0-beta.9 (1633e2ae0 2024-01-27))
https://github.com/libp2p/rust-libp2p/actions/runs/7781352784/job/21215632542 (error reported, with 1.77.0-beta.1 (04ba45219 2024-02-04))

GitHub

The Rust Implementation of the libp2p networking stack. - feat(rz): emit NewExternalAddrOfPeer when discovering peers · libp2p/rust-libp2p@caae47c

GitHub

The Rust Implementation of the libp2p networking stack. - deps: bump futures-rustls from 0.24.0 to 0.25.1 · libp2p/rust-libp2p@74de713

#

False positive clippy lint about recurison?

sage sierra
rose pasture
#

uh my latest toolchain still reports this warning, using rustc 1.77.0-beta.7 (339fb6965 2024-03-06)

#

Is that a regression or the problem is not actually solved

sage sierra
#

That's the version of rustc, not the version of clippy

rose pasture
#

I thought they were updated together

sage sierra
#

Maybe they are? idk

rose pasture
#

I have run rustup update so everything should be the latest

dusty crystal