-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
unnecessary_debug_formatting
lint (#13893)
Fixes #12674, i.e., adds a lint to flag `Path`s printed with `{:?}`. Nits are welcome. changelog: Add `unnecessary_debug_formatting` lint
- Loading branch information
Showing
10 changed files
with
314 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![feature(os_str_display)] | ||
#![warn(clippy::unnecessary_debug_formatting)] | ||
|
||
use std::ffi::{OsStr, OsString}; | ||
|
||
fn main() { | ||
let os_str = OsStr::new("abc"); | ||
let os_string = os_str.to_os_string(); | ||
|
||
// negative tests | ||
println!("{}", os_str.display()); | ||
println!("{}", os_string.display()); | ||
|
||
// positive tests | ||
println!("{:?}", os_str); //~ unnecessary_debug_formatting | ||
println!("{:?}", os_string); //~ unnecessary_debug_formatting | ||
|
||
println!("{os_str:?}"); //~ unnecessary_debug_formatting | ||
println!("{os_string:?}"); //~ unnecessary_debug_formatting | ||
|
||
let _: String = format!("{:?}", os_str); //~ unnecessary_debug_formatting | ||
let _: String = format!("{:?}", os_string); //~ unnecessary_debug_formatting | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
error: unnecessary `Debug` formatting in `println!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:15:22 | ||
| | ||
LL | println!("{:?}", os_str); | ||
| ^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_str.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
= note: `-D clippy::unnecessary-debug-formatting` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_debug_formatting)]` | ||
|
||
error: unnecessary `Debug` formatting in `println!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:16:22 | ||
| | ||
LL | println!("{:?}", os_string); | ||
| ^^^^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_string.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
|
||
error: unnecessary `Debug` formatting in `println!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:18:16 | ||
| | ||
LL | println!("{os_str:?}"); | ||
| ^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_str.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
|
||
error: unnecessary `Debug` formatting in `println!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:19:16 | ||
| | ||
LL | println!("{os_string:?}"); | ||
| ^^^^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_string.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
|
||
error: unnecessary `Debug` formatting in `format!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:21:37 | ||
| | ||
LL | let _: String = format!("{:?}", os_str); | ||
| ^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_str.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
|
||
error: unnecessary `Debug` formatting in `format!` args | ||
--> tests/ui/unnecessary_os_str_debug_formatting.rs:22:37 | ||
| | ||
LL | let _: String = format!("{:?}", os_string); | ||
| ^^^^^^^^^ | ||
| | ||
= help: use `Display` formatting and change this to `os_string.display()` | ||
= note: switching to `Display` formatting will change how the value is shown; escaped characters will no longer be escaped and surrounding quotes will be removed | ||
|
||
error: aborting due to 6 previous errors | ||
|
Oops, something went wrong.