Skip to content

ptr_arg with Path(Buf): owned Path can't be be pop'ed #6509

@matthiaskrgr

Description

@matthiaskrgr

In this code

fn new(path: &std::path::PathBuf)   {
    let _ = path.clone().pop();
}

clippy will suggest to use Path instead:

warning: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do.
 --> src/main.rs:5:14
  |
5 | fn new(path: &std::path::PathBuf)   {
  |              ^^^^^^^^^^^^^^^^^^^ help: change this to: `&Path`
  |
  = note: `#[warn(clippy::ptr_arg)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

but this is wrong because Path can't be .pop()ed.

error[E0599]: no method named `pop` found for reference `&std::path::Path` in the current scope
 --> src/main.rs:6:26
  |
6 |     let _ = path.clone().pop();
  |                          ^^^ method not found in `&std::path::Path`

error: aborting due to previous error

cc #6506
cc @alex-700

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions