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