Skip to content

Commit

Permalink
Update expr.rs
Browse files Browse the repository at this point in the history
Revert spurious changes included in PR
  • Loading branch information
compiler-errors committed Feb 12, 2022
1 parent b79fc92 commit 5be9e79
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,22 +865,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
..
}) => {
// Check if our lhs is a child of the condition of a while loop
let expr_is_ancestor = std::iter::successors(Some(lhs.hir_id), |id| {
self.tcx.hir().find_parent_node(*id)
})
.take_while(|id| *id != parent)
.any(|id| id == expr.hir_id);
// if it is, then we have a situation like `while Some(0) = value.get(0) {`,
// where `while let` was more likely intended.
if expr_is_ancestor {
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"you might have meant to use pattern destructuring",
"let ".to_string(),
Applicability::MachineApplicable,
);
}
// We have a situation like `while Some(0) = value.get(0) {`, where `while let`
// was more likely intended.
err.span_suggestion_verbose(
expr.span.shrink_to_lo(),
"you might have meant to use pattern destructuring",
"let ".to_string(),
Applicability::MachineApplicable,
);
break;
}
hir::Node::Item(_)
Expand Down

0 comments on commit 5be9e79

Please sign in to comment.