about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2025-06-21 12:28:03 +0000
committerGitHub <noreply@github.com>2025-06-21 12:28:03 +0000
commit07cc166acf074e1c6fc21d04b561e73c5d7641b6 (patch)
tree3215656fa950b15d28e42809c31dad9ea5555c52
parent7c828e63ba4ce7a6365b74dceae1474749e303d9 (diff)
parente0cb4ced0a42d137b2f85f06dd45667299863fa2 (diff)
downloadrust-07cc166acf074e1c6fc21d04b561e73c5d7641b6.tar.gz
rust-07cc166acf074e1c6fc21d04b561e73c5d7641b6.zip
Add MSRV test for `unnecessary_debug_formatting` with `OsStr` (#15001)
`unnecessary_debug_formatting` suggests display() respected for
MSRV but lacking of tests. This adds tests to check MSRV for OsStr.

changelog: none
-rw-r--r--tests/ui/unnecessary_os_str_debug_formatting.rs13
-rw-r--r--tests/ui/unnecessary_os_str_debug_formatting.stderr11
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/ui/unnecessary_os_str_debug_formatting.rs b/tests/ui/unnecessary_os_str_debug_formatting.rs
index 6652efd9ae1..66590be3d05 100644
--- a/tests/ui/unnecessary_os_str_debug_formatting.rs
+++ b/tests/ui/unnecessary_os_str_debug_formatting.rs
@@ -21,3 +21,16 @@ fn main() {
     let _: String = format!("{:?}", os_str); //~ unnecessary_debug_formatting
     let _: String = format!("{:?}", os_string); //~ unnecessary_debug_formatting
 }
+
+#[clippy::msrv = "1.86"]
+fn msrv_1_86() {
+    let os_str = OsStr::new("test");
+    println!("{:?}", os_str);
+}
+
+#[clippy::msrv = "1.87"]
+fn msrv_1_87() {
+    let os_str = OsStr::new("test");
+    println!("{:?}", os_str);
+    //~^ unnecessary_debug_formatting
+}
diff --git a/tests/ui/unnecessary_os_str_debug_formatting.stderr b/tests/ui/unnecessary_os_str_debug_formatting.stderr
index 382e59b0461..f04d2d5bdc8 100644
--- a/tests/ui/unnecessary_os_str_debug_formatting.stderr
+++ b/tests/ui/unnecessary_os_str_debug_formatting.stderr
@@ -54,5 +54,14 @@ 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
+error: unnecessary `Debug` formatting in `println!` args
+  --> tests/ui/unnecessary_os_str_debug_formatting.rs:34: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
+
+error: aborting due to 7 previous errors