Skip to content

Commit

Permalink
Auto merge of rust-lang#7242 - Jarcho:implicit_return_ice, r=flip1995
Browse files Browse the repository at this point in the history
Fix ICE in `implicit_return`

fixes: rust-lang#7231

changelog: Fix ICE in `implicit_return` for async functions
  • Loading branch information
bors committed May 18, 2021
2 parents 98cddc5 + a149ba2 commit 36be8ba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ fn lint_implicit_returns(
visit_break_exprs(block, |break_expr, dest, sub_expr| {
if dest.target_id.ok() == Some(expr.hir_id) {
if call_site_span.is_none() && break_expr.span.ctxt() == ctxt {
lint_break(cx, break_expr.span, sub_expr.unwrap().span);
// At this point sub_expr can be `None` in async functions which either diverge, or return the
// unit type.
if let Some(sub_expr) = sub_expr {
lint_break(cx, break_expr.span, sub_expr.span);
}
} else {
// the break expression is from a macro call, add a return to the loop
add_return = true;
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/crashes/ice-7231.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// edition:2018
#![allow(clippy::never_loop)]

async fn f() {
loop {
break;
}
}

fn main() {}

0 comments on commit 36be8ba

Please sign in to comment.