Skip to content

Commit 8418fb8

Browse files
committed
shorten expr_block
1 parent 42ddaa3 commit 8418fb8

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

clippy_lints/src/collapsible_if.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::source::{IntoSpan as _, SpanRangeExt, snippet, snippet_block_w
55
use clippy_utils::{span_contains_non_whitespace, tokenize_with_text};
66
use rustc_ast::BinOpKind;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{Block, Expr, ExprKind, Stmt, StmtKind};
8+
use rustc_hir::{Block, Expr, ExprKind, StmtKind};
99
use rustc_lexer::TokenKind;
1010
use rustc_lint::{LateContext, LateLintPass};
1111
use rustc_session::impl_lint_pass;
@@ -257,14 +257,9 @@ fn block_starts_with_significant_tokens(
257257
/// If `block` is a block with either one expression or a statement containing an expression,
258258
/// return the expression. We don't peel blocks recursively, as extra blocks might be intentional.
259259
fn expr_block<'tcx>(block: &Block<'tcx>) -> Option<&'tcx Expr<'tcx>> {
260-
match block.stmts {
261-
[] => block.expr,
262-
[
263-
Stmt {
264-
kind: StmtKind::Semi(expr),
265-
..
266-
},
267-
] if block.expr.is_none() => Some(expr),
260+
match (block.stmts, block.expr) {
261+
([], expr) => expr,
262+
([stmt], None) if let StmtKind::Semi(expr) = stmt.kind => Some(expr),
268263
_ => None,
269264
}
270265
}

0 commit comments

Comments
 (0)