Skip to content

Commit

Permalink
Check if let expr usage in manual_flatten
Browse files Browse the repository at this point in the history
`manual_flatten` should not trigger when match expression in `if let` is
going to be used.
  • Loading branch information
dswij committed Aug 14, 2021
1 parent bffd402 commit 8a29f65
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clippy_lints/src/loops/manual_flatten.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::utils::make_iterator_snippet;
use super::MANUAL_FLATTEN;
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::visitors::LocalUsedVisitor;
use clippy_utils::{is_lang_ctor, path_to_local_id};
use if_chain::if_chain;
use rustc_errors::Applicability;
Expand Down Expand Up @@ -47,6 +48,9 @@ pub(super) fn check<'tcx>(
let some_ctor = is_lang_ctor(cx, qpath, OptionSome);
let ok_ctor = is_lang_ctor(cx, qpath, ResultOk);
if some_ctor || ok_ctor;
// Ensure epxr in `if let` is not used afterwards
let mut used_visitor = LocalUsedVisitor::new(cx, pat_hir_id);
if !match_arms.iter().any(|arm| used_visitor.check_arm(arm));
then {
let if_let_type = if some_ctor { "Some" } else { "Ok" };
// Prepare the error message
Expand Down

0 comments on commit 8a29f65

Please sign in to comment.