Skip to content

Commit 94d06e5

Browse files
committed
Remove some unnecessary If arms
1 parent 391ebea commit 94d06e5

File tree

8 files changed

+1
-64
lines changed

8 files changed

+1
-64
lines changed

clippy_lints/src/implicit_return.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ impl ImplicitReturn {
7474
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
7575
}
7676
},
77-
ExprKind::If(.., if_expr, else_expr) => {
78-
Self::expr_match(cx, if_expr);
79-
80-
if let Some(else_expr) = else_expr {
81-
Self::expr_match(cx, else_expr);
82-
}
83-
},
8477
ExprKind::Match(.., arms, source) => {
8578
let check_all_arms = match source {
8679
MatchSource::IfLetDesugar {

clippy_lints/src/loops.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -686,14 +686,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
686686
| ExprKind::Assign(ref e1, ref e2)
687687
| ExprKind::AssignOp(_, ref e1, ref e2)
688688
| ExprKind::Index(ref e1, ref e2) => never_loop_expr_all(&mut [&**e1, &**e2].iter().cloned(), main_loop_id),
689-
ExprKind::If(ref e, ref e2, ref e3) => {
690-
let e1 = never_loop_expr(e, main_loop_id);
691-
let e2 = never_loop_expr(e2, main_loop_id);
692-
let e3 = e3
693-
.as_ref()
694-
.map_or(NeverLoopResult::Otherwise, |e| never_loop_expr(e, main_loop_id));
695-
combine_seq(e1, combine_branches(e2, e3))
696-
},
697689
ExprKind::Loop(ref b, _, _) => {
698690
// Break can come from the inner loop so remove them.
699691
absorb_break(&never_loop_block(b, main_loop_id))
@@ -2204,7 +2196,7 @@ fn is_loop(expr: &Expr) -> bool {
22042196

22052197
fn is_conditional(expr: &Expr) -> bool {
22062198
match expr.node {
2207-
ExprKind::If(..) | ExprKind::Match(..) => true,
2199+
ExprKind::Match(..) => true,
22082200
_ => false,
22092201
}
22102202
}

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,6 @@ fn lint_expect_fun_call(cx: &LateContext<'_, '_>, expr: &hir::Expr, method_span:
12661266
hir::ExprKind::Call(..)
12671267
| hir::ExprKind::MethodCall(..)
12681268
// These variants are debatable or require further examination
1269-
| hir::ExprKind::If(..)
12701269
| hir::ExprKind::Match(..)
12711270
| hir::ExprKind::Block{ .. } => true,
12721271
_ => false,

clippy_lints/src/methods/unnecessary_filter_map.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ fn check_expression<'a, 'tcx: 'a>(
8989
(false, false)
9090
}
9191
},
92-
// There must be an else_arm or there will be a type error
93-
hir::ExprKind::If(_, ref if_arm, Some(ref else_arm)) => {
94-
let if_check = check_expression(cx, arg_id, if_arm);
95-
let else_check = check_expression(cx, arg_id, else_arm);
96-
(if_check.0 | else_check.0, if_check.1 | else_check.1)
97-
},
9892
hir::ExprKind::Match(_, ref arms, _) => {
9993
let mut found_mapping = false;
10094
let mut found_filtering = false;

clippy_lints/src/utils/author.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -296,25 +296,6 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
296296
self.current = cast_pat;
297297
self.visit_expr(expr);
298298
},
299-
ExprKind::If(ref cond, ref then, ref opt_else) => {
300-
let cond_pat = self.next("cond");
301-
let then_pat = self.next("then");
302-
if let Some(ref else_) = *opt_else {
303-
let else_pat = self.next("else_");
304-
println!(
305-
"If(ref {}, ref {}, Some(ref {})) = {};",
306-
cond_pat, then_pat, else_pat, current
307-
);
308-
self.current = else_pat;
309-
self.visit_expr(else_);
310-
} else {
311-
println!("If(ref {}, ref {}, None) = {};", cond_pat, then_pat, current);
312-
}
313-
self.current = cond_pat;
314-
self.visit_expr(cond);
315-
self.current = then_pat;
316-
self.visit_expr(then);
317-
},
318299
ExprKind::While(ref cond, ref body, _) => {
319300
let cond_pat = self.next("cond");
320301
let body_pat = self.next("body");

clippy_lints/src/utils/hir_utils.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
114114
(&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => {
115115
self.eq_expr(la, ra) && self.eq_expr(li, ri)
116116
},
117-
(&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
118-
self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
119-
},
120117
(&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
121118
(&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
122119
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
@@ -493,15 +490,6 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
493490
let c: fn(_, _, _) -> _ = ExprKind::InlineAsm;
494491
c.hash(&mut self.s);
495492
},
496-
ExprKind::If(ref cond, ref t, ref e) => {
497-
let c: fn(_, _, _) -> _ = ExprKind::If;
498-
c.hash(&mut self.s);
499-
self.hash_expr(cond);
500-
self.hash_expr(&**t);
501-
if let Some(ref e) = *e {
502-
self.hash_expr(e);
503-
}
504-
},
505493
ExprKind::Lit(ref l) => {
506494
let c: fn(_) -> _ = ExprKind::Lit;
507495
c.hash(&mut self.s);

clippy_lints/src/utils/inspector.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,6 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
209209
print_expr(cx, e, indent + 1);
210210
println!("{}target type: {:?}", ind, target);
211211
},
212-
hir::ExprKind::If(ref e, _, ref els) => {
213-
println!("{}If", ind);
214-
println!("{}condition:", ind);
215-
print_expr(cx, e, indent + 1);
216-
if let Some(ref els) = *els {
217-
println!("{}else:", ind);
218-
print_expr(cx, els, indent + 1);
219-
}
220-
},
221212
hir::ExprKind::While(ref cond, _, _) => {
222213
println!("{}While", ind);
223214
println!("{}condition:", ind);

clippy_lints/src/utils/sugg.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ impl<'a> Sugg<'a> {
9494
hir::ExprKind::AddrOf(..)
9595
| hir::ExprKind::Box(..)
9696
| hir::ExprKind::Closure(.., _)
97-
| hir::ExprKind::If(..)
9897
| hir::ExprKind::Unary(..)
9998
| hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
10099
hir::ExprKind::Continue(..)

0 commit comments

Comments
 (0)