|
1 | 1 | use clippy_utils::diagnostics::span_lint_and_then; |
2 | | -use clippy_utils::higher; |
3 | 2 | use clippy_utils::res::MaybeDef; |
4 | 3 | use rustc_hir::{AssignOpKind, Expr, ExprKind, LangItem, MatchSource}; |
5 | 4 | use rustc_lint::{LateContext, LateLintPass}; |
@@ -49,22 +48,15 @@ fn is_string(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { |
49 | 48 | fn is_format(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { |
50 | 49 | let e = e.peel_blocks().peel_borrows(); |
51 | 50 |
|
52 | | - if e.span.from_expansion() |
53 | | - && let Some(macro_def_id) = e.span.ctxt().outer_expn_data().macro_def_id |
54 | | - { |
55 | | - cx.tcx.get_diagnostic_name(macro_def_id) == Some(sym::format_macro) |
56 | | - } else if let Some(higher::If { then, r#else, .. }) = higher::If::hir(e) { |
57 | | - is_format(cx, then) || r#else.is_some_and(|e| is_format(cx, e)) |
58 | | - } else { |
59 | | - match higher::IfLetOrMatch::parse(cx, e) { |
60 | | - Some(higher::IfLetOrMatch::Match(_, arms, MatchSource::Normal)) => { |
61 | | - arms.iter().any(|arm| is_format(cx, arm.body)) |
62 | | - }, |
63 | | - Some(higher::IfLetOrMatch::IfLet(_, _, then, r#else, _)) => { |
64 | | - is_format(cx, then) || r#else.is_some_and(|e| is_format(cx, e)) |
65 | | - }, |
66 | | - _ => false, |
67 | | - } |
| 51 | + match e.kind { |
| 52 | + _ if e.span.from_expansion() |
| 53 | + && let Some(macro_def_id) = e.span.ctxt().outer_expn_data().macro_def_id => |
| 54 | + { |
| 55 | + cx.tcx.is_diagnostic_item(sym::format_macro, macro_def_id) |
| 56 | + }, |
| 57 | + ExprKind::Match(_, arms, MatchSource::Normal) => arms.iter().any(|arm| is_format(cx, arm.body)), |
| 58 | + ExprKind::If(_, then, els) => is_format(cx, then) || els.is_some_and(|e| is_format(cx, e)), |
| 59 | + _ => false, |
68 | 60 | } |
69 | 61 | } |
70 | 62 |
|
|
0 commit comments