We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Warn when a Debug representation of Path is used in format! or println!, instead of path.display().
Debug
Path
format!
println!
path.display()
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.
.display()
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.
dbg!()
PathBuf
let path = Path::new("…"); println!("The path is {:?}", path);
Could be written as:
let path = Path::new("…"); println!("The path is {}", path.display());
The text was updated successfully, but these errors were encountered:
At the risk of feature creep, it might be good to warn about println!("... {} ...", path.to_string_lossy()) also.
println!("... {} ...", path.to_string_lossy())
Sorry, something went wrong.
Another reason is that I'm removing support for Debug from the executables I build:
rust-lang/rust#123940
unnecessary_debug_formatting
Successfully merging a pull request may close this issue.
What it does
Warn when a
Debug
representation ofPath
is used informat!
orprintln!
, instead ofpath.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 aPath
is incorrect: it may be used indbg!()
, or when aPathBuf
is a field in a struct that isDebug
-printed as a whole.Example
Could be written as:
The text was updated successfully, but these errors were encountered: