Skip to content

Commit 28635ff

Browse files
committed
question_mark: Lint only early returns
1 parent 05d0715 commit 28635ff

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clippy_lints/src/question_mark.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,13 @@ impl Pass {
133133
}
134134
}
135135

136-
// Check if the block has an implicit return expression
137-
if let Some(ref ret_expr) = block.expr {
138-
return Some(ret_expr.clone());
136+
// Check for `return` without a semicolon.
137+
if_chain! {
138+
if block.stmts.len() == 0;
139+
if let Some(ExprKind::Ret(Some(ret_expr))) = block.expr.as_ref().map(|e| &e.node);
140+
then {
141+
return Some(ret_expr.clone());
142+
}
139143
}
140144

141145
None

0 commit comments

Comments
 (0)