|
1 |
| -use crate::question_mark::{pat_and_expr_can_be_question_mark, QuestionMark}; |
| 1 | +use crate::question_mark::{pat_and_expr_can_be_question_mark, QuestionMark, QUESTION_MARK}; |
2 | 2 | use clippy_utils::diagnostics::span_lint_and_then;
|
3 | 3 | use clippy_utils::higher::IfLetOrMatch;
|
4 |
| -use clippy_utils::msrvs; |
5 |
| -use clippy_utils::peel_blocks; |
6 | 4 | use clippy_utils::source::snippet_with_context;
|
7 | 5 | use clippy_utils::ty::is_type_diagnostic_item;
|
8 | 6 | use clippy_utils::visitors::{Descend, Visitable};
|
9 |
| -use if_chain::if_chain; |
| 7 | +use clippy_utils::{is_lint_allowed, msrvs, peel_blocks}; |
10 | 8 | use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
11 | 9 | use rustc_errors::Applicability;
|
12 | 10 | use rustc_hir::intravisit::{walk_expr, Visitor};
|
@@ -65,12 +63,14 @@ impl<'tcx> QuestionMark {
|
65 | 63 | let Some(if_let_or_match) = IfLetOrMatch::parse(cx, init)
|
66 | 64 | {
|
67 | 65 | match if_let_or_match {
|
68 |
| - IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else) => if_chain! { |
69 |
| - if let Some(ident_map) = expr_simple_identity_map(local.pat, let_pat, if_then); |
70 |
| - if let Some(if_else) = if_else; |
71 |
| - if expr_diverges(cx, if_else); |
72 |
| - if pat_and_expr_can_be_question_mark(cx, let_pat, if_else).is_none(); |
73 |
| - then { |
| 66 | + IfLetOrMatch::IfLet(if_let_expr, let_pat, if_then, if_else) => { |
| 67 | + if |
| 68 | + let Some(ident_map) = expr_simple_identity_map(local.pat, let_pat, if_then) && |
| 69 | + let Some(if_else) = if_else && |
| 70 | + expr_diverges(cx, if_else) && |
| 71 | + let qm_allowed = is_lint_allowed(cx, QUESTION_MARK, stmt.hir_id) && |
| 72 | + (qm_allowed || pat_and_expr_can_be_question_mark(cx, let_pat, if_else).is_none()) |
| 73 | + { |
74 | 74 | emit_manual_let_else(cx, stmt.span, if_let_expr, &ident_map, let_pat, if_else);
|
75 | 75 | }
|
76 | 76 | },
|
|
0 commit comments