From e35330cabeaf312cefb4370560fd473d47eabe2d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 15 Jan 2025 16:52:46 +0100 Subject: [PATCH] Use `is_from_proc_macro` instead of checking if the snippet contains the literal --- .../src/literal_string_with_formatting_args.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/clippy_lints/src/literal_string_with_formatting_args.rs b/clippy_lints/src/literal_string_with_formatting_args.rs index c0d016ce08b0..21066a00eaf5 100644 --- a/clippy_lints/src/literal_string_with_formatting_args.rs +++ b/clippy_lints/src/literal_string_with_formatting_args.rs @@ -7,8 +7,8 @@ use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Span}; use clippy_utils::diagnostics::span_lint; +use clippy_utils::is_from_proc_macro; use clippy_utils::mir::enclosing_mir; -use clippy_utils::source::snippet_opt; declare_clippy_lint! { /// ### What it does @@ -80,8 +80,8 @@ fn emit_lint(cx: &LateContext<'_>, expr: &Expr<'_>, spans: &[(Span, Option for LiteralStringWithFormattingArg { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { +impl<'tcx> LateLintPass<'tcx> for LiteralStringWithFormattingArg { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { if expr.span.from_expansion() || expr.span.is_dummy() { return; } @@ -96,15 +96,10 @@ impl LateLintPass<'_> for LiteralStringWithFormattingArg { }, _ => return, }; - let Some(snippet) = snippet_opt(cx, expr.span) else { - return; - }; - let fmt_str = symbol.as_str(); - // If the literal has been generated by the macro, the snippet should not contain it, - // allowing us to skip it. - if !snippet.contains(fmt_str) { + if is_from_proc_macro(cx, expr) { return; } + let fmt_str = symbol.as_str(); let lo = expr.span.lo(); let mut current = fmt_str; let mut diff_len = 0;