Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unconditional_recursion false positive in PartialEq field comparison #12052

Closed
dtolnay opened this issue Dec 30, 2023 · 2 comments · Fixed by #12062
Closed

unconditional_recursion false positive in PartialEq field comparison #12052

dtolnay opened this issue Dec 30, 2023 · 2 comments · Fixed by #12062
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented Dec 30, 2023

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

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 30, 2023
@dtolnay
Copy link
Member Author

dtolnay commented Dec 30, 2023

Mentioning @GuillaumeGomez @llogiq since this lint was recently added by #11938.

dtolnay added a commit to dtolnay/get-all-crates that referenced this issue Dec 30, 2023
rust-lang/rust-clippy#12052

    warning: function cannot return without recursing
      --> src/crateversion.rs:36:5
       |
    36 | /     fn eq(&self, other: &Self) -> bool {
    37 | |         let CrateVersion {
    38 | |             version: this_version,
    39 | |             checksum: _,
    ...  |
    45 | |         this_version == other_version
    46 | |     }
       | |_____^
       |
    note: recursive call site
      --> src/crateversion.rs:45:9
       |
    45 |         this_version == other_version
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
       = note: `-W clippy::unconditional-recursion` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::unconditional_recursion)]`
@GuillaumeGomez
Copy link
Member

Thanks for the report. I'll get back to this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants