Skip to content

warn about pushing "/xy" to a path and overwriting it. #3923

Closed
@matthiaskrgr

Description

@matthiaskrgr
let mut x = PathBuf::from("/foo");
x.push("/bar");
println!("x: {}", x.display()); // "/bar"

I just ran into a situation where I did something like this, and it resulted in the path being
/bar instead of wanted /foo/bar.
What I actually wanted was

x.push("bar");

so that the path becomes /foo/bar

Could we warn about pushing an element to a pathbuf that has the file system root in it, or something like this

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsL-correctnessLint: Belongs in the correctness lint groupgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions