Skip to content

unconditional_recursion false positive in PartialEq field comparison (2) #12133

New issue

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

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

Already on GitHub? # to your account

Closed
dtolnay opened this issue Jan 12, 2024 · 1 comment · Fixed by #12137
Closed

unconditional_recursion false positive in PartialEq field comparison (2) #12133

dtolnay opened this issue Jan 12, 2024 · 1 comment · Fixed by #12137
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 Jan 12, 2024

Summary

Not the same as #12052. This happens with a nightly in which the other false positive is fixed already.

Lint Name

unconditional_recursion

Reproducer

pub struct Struct {
    field: String,
}

impl PartialEq for Struct {
    fn eq(&self, other: &Self) -> bool {
        self.field.eq(&other.field)
    }
}
warning: function cannot return without recursing
 --> src/main.rs:6:5
  |
6 | /     fn eq(&self, other: &Self) -> bool {
7 | |         self.field.eq(&other.field)
8 | |     }
  | |_____^
  |
note: recursive call site
 --> src/main.rs:7:9
  |
7 |         self.field.eq(&other.field)
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = 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 (62d7ed4a6 2024-01-11)
binary: rustc
commit-hash: 62d7ed4a6775c4490e493093ca98ef7c215b835b
commit-date: 2024-01-11
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Additional Labels

@GuillaumeGomez @xFrednet

@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 Jan 12, 2024
dtolnay added a commit to serde-rs/json that referenced this issue Jan 12, 2024
rust-lang/rust-clippy#12133

    warning: function cannot return without recursing
       --> src/map.rs:276:5
        |
    276 | /     fn eq(&self, other: &Self) -> bool {
    277 | |         self.map.eq(&other.map)
    278 | |     }
        | |_____^
        |
    note: recursive call site
       --> src/map.rs:277:9
        |
    277 |         self.map.eq(&other.map)
        |         ^^^^^^^^^^^^^^^^^^^^^^^
        = 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)]`
dtolnay added a commit to dtolnay/cargo-tally that referenced this issue Jan 12, 2024
rust-lang/rust-clippy#12133

    warning: function cannot return without recursing
      --> src/cratename.rs:47:5
       |
    47 | /     fn eq(&self, rhs: &Self) -> bool {
    48 | |         CrateNameQuery::ref_cast(&self.0).eq(CrateNameQuery::ref_cast(&rhs.0))
    49 | |     }
       | |_____^
       |
    note: recursive call site
      --> src/cratename.rs:48:9
       |
    48 |         CrateNameQuery::ref_cast(&self.0).eq(CrateNameQuery::ref_cast(&rhs.0))
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = 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)]`

    warning: function cannot return without recursing
      --> src/user.rs:42:5
       |
    42 | /     fn eq(&self, rhs: &Self) -> bool {
    43 | |         UserQuery::ref_cast(&self.0).eq(UserQuery::ref_cast(&rhs.0))
    44 | |     }
       | |_____^
       |
    note: recursive call site
      --> src/user.rs:43:9
       |
    43 |         UserQuery::ref_cast(&self.0).eq(UserQuery::ref_cast(&rhs.0))
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
dtolnay added a commit to dtolnay/syn that referenced this issue Jan 12, 2024
rust-lang/rust-clippy#12133

    warning: function cannot return without recursing
      --> src/lifetime.rs:90:5
       |
    90 | /     fn eq(&self, other: &Lifetime) -> bool {
    91 | |         self.ident.eq(&other.ident)
    92 | |     }
       | |_____^
       |
    note: recursive call site
      --> src/lifetime.rs:91:9
       |
    91 |         self.ident.eq(&other.ident)
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = 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)]`
dtolnay added a commit to dtolnay/cxx that referenced this issue Jan 12, 2024
rust-lang/rust-clippy#12133

    warning: function cannot return without recursing
      --> gen/build/src/cargo.rs:91:5
       |
    91 | /     fn eq(&self, rhs: &Self) -> bool {
    92 | |         Lookup::new(&self.0).eq(Lookup::new(&rhs.0))
    93 | |     }
       | |_____^
       |
    note: recursive call site
      --> gen/build/src/cargo.rs:92:9
       |
    92 |         Lookup::new(&self.0).eq(Lookup::new(&rhs.0))
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       = 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 issue! I'll fix it as soon as possible.

@bors bors closed this as completed in 7eca5af Jan 12, 2024
zeenix added a commit to zeenix/zbus that referenced this issue Jan 15, 2024
zeenix added a commit to zeenix/zbus that referenced this issue Jan 15, 2024
primeos-work added a commit to primeos-work/butido that referenced this issue Feb 19, 2024
The `suspicious_open_options` lint [0] warns that the truncation
behaviour should be made explicit when creating new files. We also set
`create_new(true)`, which ensures that a new file will *always* be
created so we should simply drop `create(true)` since it has no effect
anyway: "If `.create_new(true)` is set, `.create()` and `.truncate()`
are ignored." [1]

The `unconditional_recursion` lint [2] also emits a warning but that's a
false positive and should already be fixed in nightly (see [3] for a
very similar case and [4] for the PR that should fix it).
In our case we're comparing tuples with just two fields of the `Package`
structure so it isn't recursive.

[0]: https://rust-lang.github.io/rust-clippy/master/index.html#/suspicious_open_options
[1]: https://docs.rs/tokio/1.34.0/tokio/fs/struct.OpenOptions.html#method.create_new
[2]: https://rust-lang.github.io/rust-clippy/master/index.html#/unconditional_recursion
[3]: rust-lang/rust-clippy#12133
[4]: rust-lang/rust-clippy#12137
primeos-work added a commit to primeos-work/butido that referenced this issue Feb 19, 2024
The `suspicious_open_options` lint [0] warns that the truncation
behaviour should be made explicit when creating new files. We also set
`create_new(true)`, which ensures that a new file will *always* be
created so we should simply drop `create(true)` since it has no effect
anyway: "If `.create_new(true)` is set, `.create()` and `.truncate()`
are ignored." [1]

The `unconditional_recursion` lint [2] also emits a warning but that's a
false positive and should already be fixed in nightly (see [3] for a
very similar case and [4] for the PR that should fix it).
In our case we're comparing tuples with just two fields of the `Package`
structure so it isn't recursive.

[0]: https://rust-lang.github.io/rust-clippy/master/index.html#/suspicious_open_options
[1]: https://docs.rs/tokio/1.34.0/tokio/fs/struct.OpenOptions.html#method.create_new
[2]: https://rust-lang.github.io/rust-clippy/master/index.html#/unconditional_recursion
[3]: rust-lang/rust-clippy#12133
[4]: rust-lang/rust-clippy#12137

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
ammernico pushed a commit to ammernico/butido that referenced this issue Apr 30, 2024
The `suspicious_open_options` lint [0] warns that the truncation
behaviour should be made explicit when creating new files. We also set
`create_new(true)`, which ensures that a new file will *always* be
created so we should simply drop `create(true)` since it has no effect
anyway: "If `.create_new(true)` is set, `.create()` and `.truncate()`
are ignored." [1]

The `unconditional_recursion` lint [2] also emits a warning but that's a
false positive and should already be fixed in nightly (see [3] for a
very similar case and [4] for the PR that should fix it).
In our case we're comparing tuples with just two fields of the `Package`
structure so it isn't recursive.

[0]: https://rust-lang.github.io/rust-clippy/master/index.html#/suspicious_open_options
[1]: https://docs.rs/tokio/1.34.0/tokio/fs/struct.OpenOptions.html#method.create_new
[2]: https://rust-lang.github.io/rust-clippy/master/index.html#/unconditional_recursion
[3]: rust-lang/rust-clippy#12133
[4]: rust-lang/rust-clippy#12137

Signed-off-by: Michael Weiss <michael.weiss@eviden.com>
# for free to join this conversation on GitHub. Already have an account? # 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