Skip to content

Recursive PartialEq implementation not detected #99220

Open
@5225225

Description

@5225225

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=ed9fb2f62239c9485d43d48e3e0d419b

struct Foo(u32);

impl std::cmp::PartialEq for Foo {
    fn eq(&self, rhs: &Self) -> bool {
        self == rhs
    }
}

The current output is:

(no warnings)

Ideally the output should look like:

warning: function cannot return without recursing
 --> src/lib.rs:4:5
  |
4 |     fn eq(&self, rhs: &Self) -> bool {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing
5 |         self == rhs
  |         ----------- recursive call site
  |
  = note: `#[warn(unconditional_recursion)]` on by default
  = help: a `loop` may express intention better if this is on purpose

Note how we do warn about this if you do self.eq(rhs). So I guess it's a matter of treating == as .eq for the purposes of recursion checking? Not sure.

Happens on nightly/beta/stable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsL-unconditional_recursionLint: unconditional_recursionT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions