Skip to content

Commit e13b27b

Browse files
committed
don't trigger unnecessary_debug_formatting in tests
1 parent a9c61ec commit e13b27b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clippy_lints/src/format_args.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clippy_utils::macros::{
99
use clippy_utils::msrvs::{self, Msrv};
1010
use clippy_utils::source::{SpanRangeExt, snippet};
1111
use clippy_utils::ty::{implements_trait, is_type_lang_item};
12-
use clippy_utils::{is_diag_trait_item, is_from_proc_macro};
12+
use clippy_utils::{is_diag_trait_item, is_from_proc_macro, is_in_test};
1313
use itertools::Itertools;
1414
use rustc_ast::{
1515
FormatArgPosition, FormatArgPositionKind, FormatArgsPiece, FormatArgumentKind, FormatCount, FormatOptions,
@@ -484,7 +484,8 @@ impl<'tcx> FormatArgsExpr<'_, 'tcx> {
484484

485485
fn check_unnecessary_debug_formatting(&self, name: Symbol, value: &Expr<'tcx>) {
486486
let cx = self.cx;
487-
if !value.span.from_expansion()
487+
if !is_in_test(cx.tcx, value.hir_id)
488+
&& !value.span.from_expansion()
488489
&& !is_from_proc_macro(cx, value)
489490
&& let ty = cx.typeck_results().expr_ty(value)
490491
&& self.can_display_format(ty)

tests/ui/unnecessary_path_debug_formatting.rs

+6
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ fn main() {
4141
let deref_path = DerefPath { path };
4242
println!("{:?}", &*deref_path); //~ unnecessary_debug_formatting
4343
}
44+
45+
#[test]
46+
fn issue_14345() {
47+
let input = std::path::Path::new("/foo/bar");
48+
assert!(input.ends_with("baz"), "{input:?}");
49+
}

0 commit comments

Comments
 (0)