Skip to content

impl cmp::PartialEq<String> for Path is recursive #146940

@hkBst

Description

@hkBst

I tried this code:

use std::path::Path;
pub trait ParEq<Rhs = Self>
where
    Rhs: ?Sized,
{
    fn eq2(&self, other: &Rhs) -> bool;
}

impl ParEq<String> for Path {
    fn eq2(&self, other: &String) -> bool {
        self.eq2(&*other)
    }
}

fn main() {
    // &Path == &String
    Path::new("path") == &"path".to_string();
}

I expected to see this happen: works or compile error

Instead, this happened: runtime stack overflow

This is in current nightly. I believe this is due to the object of this clippy warning:

warning: function cannot return without recursing
    --> library/std/src/path.rs:3428:5
     |
3428 | /     fn eq(&self, other: &String) -> bool {
3429 | |         self == &*other
3430 | |     }
     | |_____^
     |
note: recursive call site
    --> library/std/src/path.rs:3429:9
     |
3429 |         self == &*other
     |         ^^^^^^^^^^^^^^^
     = 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::suspicious`
     = help: to override `-W clippy::suspicious` add `#[allow(clippy::unconditional_recursion)]`

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions