Skip to content

Commit 0894a9d

Browse files
committed
also lint single expression blocks
1 parent 5825b9e commit 0894a9d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

clippy_lints/src/mixed_read_write_in_expression.rs

+6
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
139139
match e.kind {
140140
// fix #10776
141141
ExprKind::Block(block, ..) => {
142+
if let Some(e) = block.expr {
143+
self.visit_expr(e);
144+
145+
return;
146+
}
147+
142148
if let Some(stmt) = block.stmts.first() && block.stmts.len() == 1 {
143149
match stmt.kind {
144150
StmtKind::Expr(e) | StmtKind::Semi(e) => self.visit_expr(e),

tests/ui/diverging_sub_expression.rs

+9
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ fn foobar() {
4040
// lint blocks as well
4141
15 => true || { return; },
4242
16 => false || { return; },
43+
// ... and when it's a single expression
44+
17 => true || { return },
45+
18 => false || { return },
46+
// ... but not when there's both an expression and a statement
47+
19 => true || { _ = 1; return },
48+
20 => false || { _ = 1; return },
49+
// ... or multiple statements
50+
21 => true || { _ = 1; return; },
51+
22 => false || { _ = 1; return; },
4352
_ => true || break,
4453
};
4554
}

0 commit comments

Comments
 (0)