Remove some unnecessary If arms
This commit is contained in:
parent
da8b56d99a
commit
69b1da4d82
@ -74,13 +74,6 @@ fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
|
||||
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 {
|
||||
|
@ -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))
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -1266,7 +1266,6 @@ fn is_call(node: &hir::ExprKind) -> bool {
|
||||
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,
|
||||
|
@ -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;
|
||||
|
@ -296,25 +296,6 @@ fn visit_expr(&mut self, expr: &Expr) {
|
||||
self.current = cast_pat;
|
||||
self.visit_expr(expr);
|
||||
},
|
||||
ExprKind::If(ref cond, ref then, ref opt_else) => {
|
||||
let cond_pat = self.next("cond");
|
||||
let then_pat = self.next("then");
|
||||
if let Some(ref else_) = *opt_else {
|
||||
let else_pat = self.next("else_");
|
||||
println!(
|
||||
"If(ref {}, ref {}, Some(ref {})) = {};",
|
||||
cond_pat, then_pat, else_pat, current
|
||||
);
|
||||
self.current = else_pat;
|
||||
self.visit_expr(else_);
|
||||
} else {
|
||||
println!("If(ref {}, ref {}, None) = {};", cond_pat, then_pat, current);
|
||||
}
|
||||
self.current = cond_pat;
|
||||
self.visit_expr(cond);
|
||||
self.current = then_pat;
|
||||
self.visit_expr(then);
|
||||
},
|
||||
ExprKind::While(ref cond, ref body, _) => {
|
||||
let cond_pat = self.next("cond");
|
||||
let body_pat = self.next("body");
|
||||
|
@ -114,9 +114,6 @@ pub fn eq_expr(&mut self, left: &Expr, right: &Expr) -> bool {
|
||||
(&ExprKind::Index(ref la, ref li), &ExprKind::Index(ref ra, ref ri)) => {
|
||||
self.eq_expr(la, ra) && self.eq_expr(li, ri)
|
||||
},
|
||||
(&ExprKind::If(ref lc, ref lt, ref le), &ExprKind::If(ref rc, ref rt, ref re)) => {
|
||||
self.eq_expr(lc, rc) && self.eq_expr(&**lt, &**rt) && both(le, re, |l, r| self.eq_expr(l, r))
|
||||
},
|
||||
(&ExprKind::Lit(ref l), &ExprKind::Lit(ref r)) => l.node == r.node,
|
||||
(&ExprKind::Loop(ref lb, ref ll, ref lls), &ExprKind::Loop(ref rb, ref rl, ref rls)) => {
|
||||
lls == rls && self.eq_block(lb, rb) && both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
|
||||
@ -493,15 +490,6 @@ pub fn hash_expr(&mut self, e: &Expr) {
|
||||
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);
|
||||
|
@ -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);
|
||||
|
@ -94,7 +94,6 @@ fn hir_from_snippet(expr: &hir::Expr, snippet: Cow<'a, str>) -> Self {
|
||||
hir::ExprKind::AddrOf(..)
|
||||
| hir::ExprKind::Box(..)
|
||||
| hir::ExprKind::Closure(.., _)
|
||||
| hir::ExprKind::If(..)
|
||||
| hir::ExprKind::Unary(..)
|
||||
| hir::ExprKind::Match(..) => Sugg::MaybeParen(snippet),
|
||||
hir::ExprKind::Continue(..)
|
||||
|
Loading…
Reference in New Issue
Block a user