Skip to content

unconditional_recursion false positive in PartialEq field comparison #12052

Closed
@dtolnay

Description

@dtolnay

Lint Name

unconditional_recursion

Reproducer

pub struct Struct {
    field: String,
}

impl PartialEq for Struct {
    fn eq(&self, other: &Self) -> bool {
        let mine = &self.field;
        let theirs = &other.field;
        mine == theirs
    }
}
warning: function cannot return without recursing
  --> src/main.rs:6:5
   |
6  | /     fn eq(&self, other: &Self) -> bool {
7  | |         let mine = &self.field;
8  | |         let theirs = &other.field;
9  | |         mine == theirs
10 | |     }
   | |_____^
   |
note: recursive call site
  --> src/main.rs:9:9
   |
9  |         mine == theirs
   |         ^^^^^^^^^^^^^^
   = 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

Version

rustc 1.77.0-nightly (3cdd004e5 2023-12-29)
binary: rustc
commit-hash: 3cdd004e55c869faa2b7b25efd3becf50346e7d6
commit-date: 2023-12-29
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions