Skip to content

Commit 8a29f65

Browse files
committed
Check if let expr usage in manual_flatten
`manual_flatten` should not trigger when match expression in `if let` is going to be used.
1 parent bffd402 commit 8a29f65

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

clippy_lints/src/loops/manual_flatten.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::utils::make_iterator_snippet;
22
use super::MANUAL_FLATTEN;
33
use clippy_utils::diagnostics::span_lint_and_then;
4+
use clippy_utils::visitors::LocalUsedVisitor;
45
use clippy_utils::{is_lang_ctor, path_to_local_id};
56
use if_chain::if_chain;
67
use rustc_errors::Applicability;
@@ -47,6 +48,9 @@ pub(super) fn check<'tcx>(
4748
let some_ctor = is_lang_ctor(cx, qpath, OptionSome);
4849
let ok_ctor = is_lang_ctor(cx, qpath, ResultOk);
4950
if some_ctor || ok_ctor;
51+
// Ensure epxr in `if let` is not used afterwards
52+
let mut used_visitor = LocalUsedVisitor::new(cx, pat_hir_id);
53+
if !match_arms.iter().any(|arm| used_visitor.check_arm(arm));
5054
then {
5155
let if_let_type = if some_ctor { "Some" } else { "Ok" };
5256
// Prepare the error message

0 commit comments

Comments
 (0)