Use is_from_proc_macro instead of checking if the snippet contains the literal
This commit is contained in:
parent
00104a4167
commit
e35330cabe
1 changed files with 5 additions and 10 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue