about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2025-01-15 16:52:46 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2025-01-15 16:56:07 +0100
commite35330cabeaf312cefb4370560fd473d47eabe2d (patch)
treeccba9fbf43ae953ccd8b8b1c81600e93ecc13e3d
parent00104a4167d2dd295e3639163dea393f7cd310d1 (diff)
downloadrust-e35330cabeaf312cefb4370560fd473d47eabe2d.tar.gz
rust-e35330cabeaf312cefb4370560fd473d47eabe2d.zip
Use `is_from_proc_macro` instead of checking if the snippet contains the literal
-rw-r--r--clippy_lints/src/literal_string_with_formatting_args.rs15
1 files 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 c0d016ce08b..21066a00eaf 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<Strin
     }
 }
 
-impl LateLintPass<'_> 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;