rust-lang / rust-lang/rust-clippy
Use `Path::new` instead of `&PathBuf::from`
Open
Nobody has claimed this yet.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
PathBuf::from does allocation, but if &Path is needed, there is no point in having &PathBuf::from(...)
Advantage
- performance and clarity
Drawbacks
No response
Example
fn use_path(p: &Path) {}
use_path(&PathBuf::from("abc"));
Could be written as:
use_path(Path::new("abc"));
Comparison with existing lints
No response
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating existing Rust Clippy lints that suggest simpler path handling and study their implementation and test structure. Use the issue's PathBuf::from and Path::new examples to define the expected diagnostic, then add coverage showing the lint recognizes the described pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100