diff options
| author | yanglsh <yanglsh@shanghaitech.edu.cn> | 2025-05-03 20:31:47 +0800 |
|---|---|---|
| committer | yanglsh <yanglsh@shanghaitech.edu.cn> | 2025-05-06 14:25:21 +0800 |
| commit | e7acf5c9b91bf9f2bd79fbb1de77f65cdd73c8e5 (patch) | |
| tree | e3b84edae8bb5fe3bbea38035bf705d4f99ef841 /clippy_lints/src | |
| parent | 50e0bf1b71b802d51b4de8343ed3f4b48d0782b5 (diff) | |
fix: `collapsible_if` FP on block stmt before expr
Diffstat (limited to 'clippy_lints/src')
| -rw-r--r-- | clippy_lints/src/collapsible_if.rs | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/clippy_lints/src/collapsible_if.rs b/clippy_lints/src/collapsible_if.rs index b231f05ed88..7f6ecea99fb 100644 --- a/clippy_lints/src/collapsible_if.rs +++ b/clippy_lints/src/collapsible_if.rs @@ -4,7 +4,7 @@ use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::{IntoSpan as _, SpanRangeExt, snippet, snippet_block, snippet_block_with_applicability}; use rustc_ast::BinOpKind; use rustc_errors::Applicability; -use rustc_hir::{Block, Expr, ExprKind, StmtKind}; +use rustc_hir::{Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::impl_lint_pass; use rustc_span::Span; @@ -203,13 +203,12 @@ fn block_starts_with_comment(cx: &LateContext<'_>, block: &Block<'_>) -> bool { fn expr_block<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> { match block.stmts { [] => block.expr, - [stmt] => { - if let StmtKind::Semi(expr) = stmt.kind { - Some(expr) - } else { - None - } - }, + [ + Stmt { + kind: StmtKind::Semi(expr), + .. + }, + ] if block.expr.is_none() => Some(expr), _ => None, } } |
