Skip to content

Commit

Permalink
Use is_from_proc_macro instead of checking if the snippet contains …
Browse files Browse the repository at this point in the history
…the literal
  • Loading branch information
GuillaumeGomez committed Jan 15, 2025
1 parent 00104a4 commit e35330c
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions clippy_lints/src/literal_string_with_formatting_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit e35330c

Please sign in to comment.