-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
What it does
Detect uses of print
(instead of write
) and similar inside of implementations of formatting traits (Debug, Display, LowerHex, etc.)
Categories (optional)
- Kind: correctness
What is the advantage of the recommended code over the original code
Using print will appear to work correctly until one tries to print somewhere other than stdout (a file, string buffer, ...)
Drawbacks
None.
Example
impl fmt::Display for Test {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
println!("Hello");
writeln!(f, "there!")
}
}
Should be written as:
impl fmt::Display for Test {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
writeln!(f, "Hello")?;
writeln!(f, "there!")
}
}
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy