mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
Correctly handle expanded macros for literal_string_with_formatting_args lint
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::mir::enclosing_mir;
|
||||
use clippy_utils::source::snippet_opt;
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
@@ -95,7 +96,15 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
},
|
||||
_ => 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) {
|
||||
return;
|
||||
}
|
||||
let lo = expr.span.lo();
|
||||
let mut current = fmt_str;
|
||||
let mut diff_len = 0;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// Regression test for <https://github.com/rust-lang/rust-clippy/issues/13885>.
|
||||
// The `dbg` macro generates a literal with the name of the current file, so
|
||||
// we need to ensure the lint is not emitted in this case.
|
||||
|
||||
#![crate_name = "foo"]
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::literal_string_with_formatting_args)]
|
||||
|
||||
fn another_bad() {
|
||||
let literal_string_with_formatting_args = 0;
|
||||
dbg!("something");
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Reference in New Issue
Block a user