Skip to content

Commit

Permalink
Remove some unnecessary If arms
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 11, 2019
1 parent 206eb79 commit af9e59d
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 42 deletions.
7 changes: 0 additions & 7 deletions clippy_lints/src/implicit_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ impl ImplicitReturn {
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
}
},
ExprKind::If(.., if_expr, else_expr) => {
Self::expr_match(cx, if_expr);

if let Some(else_expr) = else_expr {
Self::expr_match(cx, else_expr);
}
},
ExprKind::Match(.., arms, source) => {
let check_all_arms = match source {
MatchSource::IfLetDesugar {
Expand Down
10 changes: 1 addition & 9 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
| ExprKind::Assign(ref e1, ref e2)
| ExprKind::AssignOp(_, ref e1, ref e2)
| ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id),
ExprKind::If(ref e, ref e2, ref e3) => {
let e1 = never_loop_expr(e, main_loop_id);
let e2 = never_loop_expr(e2, main_loop_id);
let e3 = e3
.as_ref()
.map_or(NeverLoopResult::Otherwise, |e| never_loop_expr(e, main_loop_id));
combine_seq(e1, combine_branches(e2, e3))
},
ExprKind::Loop(ref b, _, _) => {
// Break can come from the inner loop so remove them.
absorb_break(&never_loop_block(b, main_loop_id))
Expand Down Expand Up @@ -2204,7 +2196,7 @@ fn is_loop(expr: &Expr) -> bool {

fn is_conditional(expr: &Expr) -> bool {
match expr.node {
ExprKind::If(..) | ExprKind::Match(..) => true,
ExprKind::Match(..) => true,
_ => false,
}
}
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
hir::ExprKind::Call(..)
| hir::ExprKind::MethodCall(..)
// These variants are debatable or require further examination
| hir::ExprKind::If(..)
| hir::ExprKind::Match(..)
| hir::ExprKind::Block{ .. } => true,
_ => false,
Expand Down
6 changes: 0 additions & 6 deletions clippy_lints/src/methods/unnecessary_filter_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ fn check_expression<'a, 'tcx: 'a>(
(false, false)
}
},
// There must be an else_arm or there will be a type error
hir::ExprKind::If(_, ref if_arm, Some(ref else_arm)) => {
let if_check = check_expression(cx, arg_id, if_arm);
let else_check = check_expression(cx, arg_id, else_arm);
(if_check.0 | else_check.0, if_check.1 | else_check.1)
},
hir::ExprKind::Match(_, ref arms, _) => {
let mut found_mapping = false;
let mut found_filtering = false;
Expand Down
9 changes: 0 additions & 9 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
c.hash(&mut self.s);
},
ExprKind::If(ref cond, ref t, ref e) => {
let c: fn(_, _, _) -> _ = ExprKind::If;
c.hash(&mut self.s);
self.hash_expr(cond);
self.hash_expr(&**t);
if let Some(ref e) = *e {
self.hash_expr(e);
}
},
ExprKind::Lit(ref l) => {
let c: fn(_) -> _ = ExprKind::Lit;
c.hash(&mut self.s);
Expand Down
9 changes: 0 additions & 9 deletions clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,6 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
print_expr(cx, e, indent + 1);
println!("{}target type: {:?}", ind, target);
},
hir::ExprKind::If(ref e, _, ref els) => {
println!("{}If", ind);
println!("{}condition:", ind);
print_expr(cx, e, indent + 1);
if let Some(ref els) = *els {
println!("{}else:", ind);
print_expr(cx, els, indent + 1);
}
},
hir::ExprKind::While(ref cond, _, _) => {
println!("{}While", ind);
println!("{}condition:", ind);
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/utils/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl<'a> Sugg<'a> {
hir::ExprKind::AddrOf(..)
| hir::ExprKind::Box(..)
| hir::ExprKind::Closure(.., _)
| hir::ExprKind::If(..)
| hir::ExprKind::Unary(..)
| hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
hir::ExprKind::Continue(..)
Expand Down

0 comments on commit af9e59d

Please sign in to comment.