diff options
| author | Mario Carneiro <di.gama@gmail.com> | 2023-09-02 07:32:38 -0400 |
|---|---|---|
| committer | Mario Carneiro <di.gama@gmail.com> | 2023-09-02 07:32:38 -0400 |
| commit | 39b316db61f350f5aafb186ab4b919587ead4777 (patch) | |
| tree | bcf3762244c3c1c42cb97a3926841b881916f9bb | |
| parent | 68011893d82e5923e894673d018a5d803d6da20c (diff) | |
| download | rust-39b316db61f350f5aafb186ab4b919587ead4777.tar.gz rust-39b316db61f350f5aafb186ab4b919587ead4777.zip | |
an empty match diverges
| -rw-r--r-- | clippy_lints/src/loops/never_loop.rs | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/clippy_lints/src/loops/never_loop.rs b/clippy_lints/src/loops/never_loop.rs index ee1bf67994e..13f0ddc0ebf 100644 --- a/clippy_lints/src/loops/never_loop.rs +++ b/clippy_lints/src/loops/never_loop.rs @@ -194,13 +194,11 @@ fn never_loop_expr<'tcx>( }, ExprKind::Match(e, arms, _) => { let e = never_loop_expr(cx, e, local_labels, main_loop_id); - if arms.is_empty() { - e - } else { - combine_seq(e, || { - never_loop_expr_branch(cx, &mut arms.iter().map(|a| a.body), local_labels, main_loop_id) + combine_seq(e, || { + arms.iter().fold(NeverLoopResult::Diverging, |a, b| { + combine_branches(a, never_loop_expr(cx, b.body, local_labels, main_loop_id)) }) - } + }) }, ExprKind::Block(b, l) => { if l.is_some() { @@ -276,17 +274,6 @@ fn never_loop_expr_all<'tcx, T: Iterator<Item = &'tcx Expr<'tcx>>>( combine_seq_many(es.map(|e| never_loop_expr(cx, e, local_labels, main_loop_id))) } -fn never_loop_expr_branch<'tcx, T: Iterator<Item = &'tcx Expr<'tcx>>>( - cx: &LateContext<'tcx>, - e: &mut T, - local_labels: &mut Vec<(HirId, bool)>, - main_loop_id: HirId, -) -> NeverLoopResult { - e.fold(NeverLoopResult::Diverging, |a, b| { - combine_branches(a, never_loop_expr(cx, b, local_labels, main_loop_id)) - }) -} - fn for_to_if_let_sugg(cx: &LateContext<'_>, iterator: &Expr<'_>, pat: &Pat<'_>) -> String { let pat_snippet = snippet(cx, pat.span, "_"); let iter_snippet = make_iterator_snippet(cx, iterator, &mut Applicability::Unspecified); |
