Also ignore continue statements in is_unit_expr

This commit is contained in:
Oliver Schneider 2017-09-05 11:25:20 +02:00 committed by Manish Goregaokar
parent 7e9ba81297
commit 8c824e4cbc
2 changed files with 33 additions and 3 deletions

View file

@ -98,6 +98,7 @@ impl EarlyLintPass for UnitExpr {
}
}
}
fn is_unit_expr(expr: &Expr) -> Option<Span> {
match expr.node {
ExprKind::Block(ref block) => if check_last_stmt_in_block(block) {
@ -139,9 +140,13 @@ fn check_last_stmt_in_block(block: &Block) -> bool {
// like `panic!()`
match final_stmt.node {
StmtKind::Expr(_) => false,
StmtKind::Semi(ref expr) => match expr.node {
ExprKind::Break(_, _) | ExprKind::Ret(_) => false,
_ => true,
StmtKind::Semi(ref expr) => {
match expr.node {
ExprKind::Break(_, _) |
ExprKind::Continue(_) |
ExprKind::Ret(_) => false,
_ => true,
}
},
_ => true,
}

View file

@ -45,4 +45,29 @@ fn main() {
0;
},
};
loop {
let a2 = match a1 {
Some(x) => x,
_ => {
break;
},
};
let a2 = match a1 {
Some(x) => x,
_ => {
continue;
},
};
}
}
pub fn foo() -> i32 {
let a2 = match None {
Some(x) => x,
_ => {
return 42;
},
};
55
}