mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
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:
commit
1c01ff5200
2 changed files with 33 additions and 3 deletions
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue