Skip to content

Paths printed with {:?} instead of .display() #12674

Closed
@kornelski

Description

@kornelski

What it does

Warn when a Debug representation of Path is used in format! or println!, instead of path.display().

Advantage

Rust doesn't guarantee how Debug formatting looks like, and it could change in the future. For printing paths there's the dedicated .display() method.

Drawbacks

Not every Debug print of a Path is incorrect: it may be used in dbg!(), or when a PathBuf is a field in a struct that is Debug-printed as a whole.

Example

let path = Path::new("…");
println!("The path is {:?}", path);

Could be written as:

let path = Path::new("…");
println!("The path is {}", path.display());

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