Skip to content

Checking a &PathBuf and a &str for equality leads to a stack overflow #146183

Description

@fmease

Reproducer (nightly 1.91):

fn main() {
    _ = &std::path::PathBuf::from("x") == "-";
}

or

fn main() {
    _ = "-" == &std::path::PathBuf::from("x");
}

When run, it leads to a stack overflow. Output in debug mode (hangs in release):

thread 'main' (157) has overflowed its stack
fatal runtime error: stack overflow, aborting

_ = std::path::Path::new("x") == "-"; does not reproduce this stack overflow.
Neither does this: _ = &std::path::PathBuf::from("x") == std::path::Path::new("-");.

This might be related to the recent addition of PartialEq<str> for Path, PartialEq<str> for PathBuf and friends on nightly (1.91).


rustc 1.91.0-nightly (51ff89506 2025-09-02)
binary: rustc
commit-hash: 51ff895062ba60a7cba53f57af928c3fb7b0f2f4
commit-date: 2025-09-02
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

Also reproduces on the playground (nightly).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions