Skip to content

unnecessary_debug_formatting respect MSRV #15001

New issue

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
* [`type_repetition_in_bounds`](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds)
* [`unchecked_duration_subtraction`](https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction)
* [`uninlined_format_args`](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args)
* [`unnecessary_debug_formatting`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_debug_formatting)
* [`unnecessary_lazy_evaluations`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations)
* [`unnested_or_patterns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns)
* [`unused_trait_names`](https://rust-lang.github.io/rust-clippy/master/index.html#unused_trait_names)
Expand Down
1 change: 1 addition & 0 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ define_Conf! {
type_repetition_in_bounds,
unchecked_duration_subtraction,
uninlined_format_args,
unnecessary_debug_formatting,
unnecessary_lazy_evaluations,
unnested_or_patterns,
unused_trait_names,
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> {
&& !is_from_proc_macro(cx, value)
&& let ty = cx.typeck_results().expr_ty(value)
&& self.can_display_format(ty)
&& self.msrv.meets(cx, msrvs::UNNECESSARY_DEBUG_FORMATTING)
{
// If the parent function is a method of `Debug`, we don't want to lint
// because it is likely that the user wants to use `Debug` formatting.
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! msrv_aliases {
// names may refer to stabilized feature flags or library items
msrv_aliases! {
1,88,0 { LET_CHAINS }
1,87,0 { OS_STR_DISPLAY, INT_MIDPOINT, CONST_CHAR_IS_DIGIT }
1,87,0 { OS_STR_DISPLAY, INT_MIDPOINT, CONST_CHAR_IS_DIGIT, UNNECESSARY_DEBUG_FORMATTING }
1,85,0 { UINT_FLOAT_MIDPOINT, CONST_SIZE_OF_VAL }
1,84,0 { CONST_OPTION_AS_SLICE, MANUAL_DANGLING_PTR }
1,83,0 { CONST_EXTERN_FN, CONST_FLOAT_BITS_CONV, CONST_FLOAT_CLASSIFY, CONST_MUT_REFS, CONST_UNWRAP }
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/unnecessary_os_str_debug_formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ 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");

// Should not lint because MSRV is 1.86, but display() was stabilized in 1.87
println!("{:?}", os_str);
}

#[clippy::msrv = "1.87"]
fn msrv_1_87() {
let os_str = OsStr::new("test");

// Should lint because MSRV is 1.87 and display() is available
println!("{:?}", os_str);
//~^ unnecessary_debug_formatting
}
11 changes: 10 additions & 1 deletion tests/ui/unnecessary_os_str_debug_formatting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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:38: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

22 changes: 22 additions & 0 deletions tests/ui/unnecessary_path_debug_formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,25 @@ fn issue_14345() {
let input = std::path::Path::new("/foo/bar");
assert!(input.ends_with("baz"), "{input:?}");
}

#[clippy::msrv = "1.86"]
fn msrv_1_86() {
let path = Path::new("/test");
let path_buf = PathBuf::from("/test");

// Should not lint because MSRV is 1.86, but display() was stabilized in 1.87
println!("{:?}", path);
println!("{:?}", path_buf);
}

#[clippy::msrv = "1.87"]
fn msrv_1_87() {
let path = Path::new("/test");
let path_buf = PathBuf::from("/test");

// Should lint because MSRV is 1.87 and display() is available
println!("{:?}", path);
//~^ unnecessary_debug_formatting
println!("{:?}", path_buf);
//~^ unnecessary_debug_formatting
}
20 changes: 19 additions & 1 deletion tests/ui/unnecessary_path_debug_formatting.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,23 @@ LL | println!("{:?}", &*deref_path);
= help: use `Display` formatting and change this to `&*deref_path.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 9 previous errors
error: unnecessary `Debug` formatting in `println!` args
--> tests/ui/unnecessary_path_debug_formatting.rs:68:22
|
LL | println!("{:?}", path);
| ^^^^
|
= help: use `Display` formatting and change this to `path.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_path_debug_formatting.rs:70:22
|
LL | println!("{:?}", path_buf);
| ^^^^^^^^
|
= help: use `Display` formatting and change this to `path_buf.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 11 previous errors

Loading