Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matthiaskrgr opened this issue Dec 27, 2020 · 0 comments · Fixed by #6510
Closed

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

matthiaskrgr opened this issue Dec 27, 2020 · 0 comments · Fixed by #6510
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@matthiaskrgr
Copy link
Member

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

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Dec 27, 2020
@matthiaskrgr matthiaskrgr changed the title part_arg: owned path can't be be pop'ed ptr_arg with Path(Buf): owned path can't be be pop'ed Dec 27, 2020
@matthiaskrgr matthiaskrgr changed the title ptr_arg with Path(Buf): owned path can't be be pop'ed ptr_arg with Path(Buf): owned Path can't be be pop'ed Dec 27, 2020
@bors bors closed this as completed in 0d8a27a Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant