Skip to content

Commit a149ba2

Browse files
committed
Fix ICE in implicit_return
async functions always return a value
1 parent 98cddc5 commit a149ba2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clippy_lints/src/implicit_return.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ fn lint_implicit_returns(
147147
visit_break_exprs(block, |break_expr, dest, sub_expr| {
148148
if dest.target_id.ok() == Some(expr.hir_id) {
149149
if call_site_span.is_none() && break_expr.span.ctxt() == ctxt {
150-
lint_break(cx, break_expr.span, sub_expr.unwrap().span);
150+
// At this point sub_expr can be `None` in async functions which either diverge, or return the
151+
// unit type.
152+
if let Some(sub_expr) = sub_expr {
153+
lint_break(cx, break_expr.span, sub_expr.span);
154+
}
151155
} else {
152156
// the break expression is from a macro call, add a return to the loop
153157
add_return = true;

tests/ui/crashes/ice-7231.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// edition:2018
2+
#![allow(clippy::never_loop)]
3+
4+
async fn f() {
5+
loop {
6+
break;
7+
}
8+
}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)