Skip to content

Use Path::new instead of &PathBuf::from #15637

@nyurik

Description

@nyurik

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions