This commit is contained in:
Centri3 2023-06-09 15:32:42 -05:00
parent c1c134a288
commit 35aff1ae86
3 changed files with 10 additions and 14 deletions

View File

@ -138,19 +138,13 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
fn visit_expr(&mut self, e: &'tcx Expr<'_>) {
match e.kind {
// fix #10776
ExprKind::Block(block, ..) => {
if let Some(e) = block.expr && block.stmts.is_empty() {
self.visit_expr(e);
return;
}
if let [stmt, rest @ ..] = block.stmts && rest.is_empty() {
match stmt.kind {
StmtKind::Expr(e) | StmtKind::Semi(e) => self.visit_expr(e),
_ => {},
}
}
ExprKind::Block(block, ..) => match (block.stmts, block.expr) {
([], Some(e)) => self.visit_expr(e),
([stmt], None) => match stmt.kind {
StmtKind::Expr(e) | StmtKind::Semi(e) => self.visit_expr(e),
_ => {},
},
_ => {},
},
ExprKind::Continue(_) | ExprKind::Break(_, _) | ExprKind::Ret(_) => self.report_diverging_sub_expr(e),
ExprKind::Call(func, _) => {

View File

@ -49,6 +49,8 @@ fn foobar() {
// ... or multiple statements
21 => true || { _ = 1; return; },
22 => false || { _ = 1; return; },
23 => true || { return; true },
24 => true || { return; true },
_ => true || break,
};
}

View File

@ -63,7 +63,7 @@ LL | 18 => false || { return },
| ^^^^^^
error: sub-expression diverges
--> $DIR/diverging_sub_expression.rs:52:26
--> $DIR/diverging_sub_expression.rs:54:26
|
LL | _ => true || break,
| ^^^^^