Skip to content

Commit

Permalink
Auto merge of #4258 - mikerite:fix-breakage-20190706, r=Manishearth
Browse files Browse the repository at this point in the history
Fix breakage due to rust-lang/rust#61988

changelog: none
  • Loading branch information
bors committed Jul 6, 2019
2 parents 5d7f6a1 + adcc02e commit 61204dc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 60 deletions.
37 changes: 13 additions & 24 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,16 +481,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
}

// check for never_loop
match expr.node {
ExprKind::While(_, ref block, _) | ExprKind::Loop(ref block, _, _) => {
match never_loop_block(block, expr.hir_id) {
NeverLoopResult::AlwaysBreak => {
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
},
NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
}
},
_ => (),
if let ExprKind::Loop(ref block, _, _) = expr.node {
match never_loop_block(block, expr.hir_id) {
NeverLoopResult::AlwaysBreak => {
span_lint(cx, NEVER_LOOP, expr.span, "this loop never actually loops")
},
NeverLoopResult::MayContinueMainLoop | NeverLoopResult::Otherwise => (),
}
}

// check for `loop { if let {} else break }` that could be `while let`
Expand Down Expand Up @@ -590,9 +587,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Loops {
}
}

// check for while loops which conditions never change
if let ExprKind::While(ref cond, _, _) = expr.node {
check_infinite_loop(cx, cond, expr);
if let Some((cond, body)) = higher::while_loop(&expr) {
check_infinite_loop(cx, cond, body);
}

check_needless_collect(expr, cx);
Expand Down Expand Up @@ -701,12 +697,6 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult {
// Break can come from the inner loop so remove them.
absorb_break(&never_loop_block(b, main_loop_id))
},
ExprKind::While(ref e, ref b, _) => {
let e = never_loop_expr(e, main_loop_id);
let result = never_loop_block(b, main_loop_id);
// Break can come from the inner loop so remove them.
combine_seq(e, absorb_break(&result))
},
ExprKind::Match(ref e, ref arms, _) => {
let e = never_loop_expr(e, main_loop_id);
if arms.is_empty() {
Expand Down Expand Up @@ -2202,7 +2192,7 @@ fn var_def_id(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<HirId> {

fn is_loop(expr: &Expr) -> bool {
match expr.node {
ExprKind::Loop(..) | ExprKind::While(..) => true,
ExprKind::Loop(..) => true,
_ => false,
}
}
Expand Down Expand Up @@ -2239,11 +2229,10 @@ fn is_loop_nested(cx: &LateContext<'_, '_>, loop_expr: &Expr, iter_expr: &Expr)
return false;
}
match cx.tcx.hir().find(parent) {
Some(Node::Expr(expr)) => match expr.node {
ExprKind::Loop(..) | ExprKind::While(..) => {
Some(Node::Expr(expr)) => {
if let ExprKind::Loop(..) = expr.node {
return true;
},
_ => (),
};
},
Some(Node::Block(block)) => {
let mut block_visitor = LoopNestVisitor {
Expand Down
4 changes: 0 additions & 4 deletions clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,6 @@ fn check_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, bindings:
check_expr(cx, e, bindings)
}
},
ExprKind::While(ref cond, ref block, _) => {
check_expr(cx, cond, bindings);
check_block(cx, block, bindings);
},
ExprKind::Match(ref init, ref arms, _) => {
check_expr(cx, init, bindings);
let len = bindings.len();
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/unused_label.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnusedLabelVisitor<'a, 'tcx> {
self.labels.remove(&label.ident.as_str());
}
},
hir::ExprKind::Loop(_, Some(label), _) | hir::ExprKind::While(_, _, Some(label)) => {
hir::ExprKind::Loop(_, Some(label), _) => {
self.labels.insert(label.ident.as_str(), expr.span);
},
_ => (),
Expand Down
15 changes: 2 additions & 13 deletions clippy_lints/src/utils/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,6 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
self.current = cast_pat;
self.visit_expr(expr);
},
ExprKind::While(ref cond, ref body, _) => {
let cond_pat = self.next("cond");
let body_pat = self.next("body");
let label_pat = self.next("label");
println!(
"While(ref {}, ref {}, ref {}) = {};",
cond_pat, body_pat, label_pat, current
);
self.current = cond_pat;
self.visit_expr(cond);
self.current = body_pat;
self.visit_block(body);
},
ExprKind::Loop(ref body, _, desugaring) => {
let body_pat = self.next("body");
let des = loop_desugaring_name(desugaring);
Expand Down Expand Up @@ -696,6 +683,7 @@ fn desugaring_name(des: hir::MatchSource) -> String {
match des {
hir::MatchSource::ForLoopDesugar => "MatchSource::ForLoopDesugar".to_string(),
hir::MatchSource::TryDesugar => "MatchSource::TryDesugar".to_string(),
hir::MatchSource::WhileDesugar => "MatchSource::WhileDesugar".to_string(),
hir::MatchSource::WhileLetDesugar => "MatchSource::WhileLetDesugar".to_string(),
hir::MatchSource::Normal => "MatchSource::Normal".to_string(),
hir::MatchSource::IfLetDesugar { contains_else_clause } => format!(
Expand All @@ -714,6 +702,7 @@ fn loop_desugaring_name(des: hir::LoopSource) -> &'static str {
match des {
hir::LoopSource::ForLoop => "LoopSource::ForLoop",
hir::LoopSource::Loop => "LoopSource::Loop",
hir::LoopSource::While => "LoopSource::While",
hir::LoopSource::WhileLet => "LoopSource::WhileLet",
}
}
Expand Down
17 changes: 17 additions & 0 deletions clippy_lints/src/utils/higher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,23 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
None
}

/// Recover the essential nodes of a desugared while loop:
/// `while cond { body }` becomes `(cond, body)`.
pub fn while_loop(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr)> {
if_chain! {
if let hir::ExprKind::Loop(block, _, hir::LoopSource::While) = &expr.node;
if let hir::Block { expr: Some(expr), .. } = &**block;
if let hir::ExprKind::Match(cond, arms, hir::MatchSource::WhileDesugar) = &expr.node;
if let hir::ExprKind::DropTemps(cond) = &cond.node;
if let [arm, ..] = &arms[..];
if let hir::Arm { body, .. } = arm;
then {
return Some((cond, body));
}
}
None
}

/// Recover the essential nodes of a desugared if block
/// `if cond { then } else { els }` becomes `(cond, then, Some(els))`
pub fn if_block(expr: &hir::Expr) -> Option<(&hir::Expr, &hir::Expr, Option<&hir::Expr>)> {
Expand Down
12 changes: 0 additions & 12 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
(&ExprKind::Tup(ref l_tup), &ExprKind::Tup(ref r_tup)) => self.eq_exprs(l_tup, r_tup),
(&ExprKind::Unary(l_op, ref le), &ExprKind::Unary(r_op, ref re)) => l_op == r_op && self.eq_expr(le, re),
(&ExprKind::Array(ref l), &ExprKind::Array(ref r)) => self.eq_exprs(l, r),
(&ExprKind::While(ref lc, ref lb, ref ll), &ExprKind::While(ref rc, ref rb, ref rl)) => {
self.eq_expr(lc, rc)
&& self.eq_block(lb, rb)
&& both(ll, rl, |l, r| l.ident.as_str() == r.ident.as_str())
},
(&ExprKind::DropTemps(ref le), &ExprKind::DropTemps(ref re)) => self.eq_expr(le, re),
_ => false,
}
Expand Down Expand Up @@ -524,13 +519,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
lop.hash(&mut self.s);
self.hash_expr(le);
},
ExprKind::While(ref cond, ref b, l) => {
self.hash_expr(cond);
self.hash_block(b);
if let Some(l) = l {
self.hash_name(l.ident.name);
}
},
}
}

Expand Down
5 changes: 0 additions & 5 deletions clippy_lints/src/utils/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +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::While(ref cond, _, _) => {
println!("{}While", ind);
println!("{}condition:", ind);
print_expr(cx, cond, indent + 1);
},
hir::ExprKind::Loop(..) => {
println!("{}Loop", 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 @@ -113,7 +113,6 @@ impl<'a> Sugg<'a> {
| hir::ExprKind::Ret(..)
| hir::ExprKind::Struct(..)
| hir::ExprKind::Tup(..)
| hir::ExprKind::While(..)
| hir::ExprKind::DropTemps(_)
| hir::ExprKind::Err => Sugg::NonParen(snippet),
hir::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),
Expand Down

0 comments on commit 61204dc

Please sign in to comment.