Merge pull request #2022 from rust-lang-nursery/oli-obk-patch-1

Also ignore `continue` statements in `is_unit_expr`
This commit is contained in:
Manish Goregaokar 2017-09-05 13:30:40 -07:00 committed by GitHub
commit 1c01ff5200
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> { fn is_unit_expr(expr: &Expr) -> Option<Span> {
match expr.node { match expr.node {
ExprKind::Block(ref block) => if check_last_stmt_in_block(block) { 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!()` // like `panic!()`
match final_stmt.node { match final_stmt.node {
StmtKind::Expr(_) => false, StmtKind::Expr(_) => false,
StmtKind::Semi(ref expr) => match expr.node { StmtKind::Semi(ref expr) => {
ExprKind::Break(_, _) | ExprKind::Ret(_) => false, match expr.node {
_ => true, ExprKind::Break(_, _) |
ExprKind::Continue(_) |
ExprKind::Ret(_) => false,
_ => true,
}
}, },
_ => true, _ => true,
} }

View file

@ -45,4 +45,29 @@ fn main() {
0; 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
} }