@@ -4,16 +4,16 @@ use clippy_utils::msrvs::Msrv;
4
4
use clippy_utils::source::snippet_with_applicability;
5
5
use clippy_utils::ty::is_type_diagnostic_item;
6
6
use clippy_utils::{
7
- eq_expr_value, get_parent_node, in_constant, is_else_clause, is_refutable, is_res_lang_ctor, path_to_local ,
8
- path_to_local_id, peel_blocks, peel_blocks_with_stmt,
7
+ eq_expr_value, get_parent_node, in_constant, is_else_clause, is_res_lang_ctor, pat_and_expr_can_be_question_mark ,
8
+ path_to_local, path_to_local_id, peel_blocks, peel_blocks_with_stmt,
9
9
};
10
10
use clippy_utils::{higher, is_path_lang_item};
11
11
use if_chain::if_chain;
12
12
use rustc_errors::Applicability;
13
13
use rustc_hir::def::Res;
14
14
use rustc_hir::LangItem::{self, OptionNone, OptionSome, ResultErr, ResultOk};
15
15
use rustc_hir::{
16
- BindingAnnotation, Block, ByRef, Expr, ExprKind, Local, Node, Pat, PatKind, PathSegment, QPath, Stmt, StmtKind,
16
+ BindingAnnotation, Block, ByRef, Expr, ExprKind, Local, Node, PatKind, PathSegment, QPath, Stmt, StmtKind,
17
17
};
18
18
use rustc_lint::{LateContext, LateLintPass};
19
19
use rustc_middle::ty::Ty;
@@ -95,50 +95,6 @@ enum IfBlockType<'hir> {
95
95
),
96
96
}
97
97
98
- /// Returns whether the given let pattern and else body can be turned into a question mark
99
- ///
100
- /// For this example:
101
- /// ```ignore
102
- /// let FooBar { a, b } = if let Some(a) = ex { a } else { return None };
103
- /// ```
104
- /// We get as parameters:
105
- /// ```ignore
106
- /// pat: Some(a)
107
- /// else_body: return None
108
- /// ```
109
-
110
- /// And for this example:
111
- /// ```ignore
112
- /// let Some(FooBar { a, b }) = ex else { return None };
113
- /// ```
114
- /// We get as parameters:
115
- /// ```ignore
116
- /// pat: Some(FooBar { a, b })
117
- /// else_body: return None
118
- /// ```
119
-
120
- /// We output `Some(a)` in the first instance, and `Some(FooBar { a, b })` in the second, because
121
- /// the question mark operator is applicable here. Callers have to check whether we are in a
122
- /// constant or not.
123
- pub(crate) fn pat_and_expr_can_be_question_mark<'a, 'hir>(
124
- cx: &LateContext<'_>,
125
- pat: &'a Pat<'hir>,
126
- else_body: &Expr<'_>,
127
- ) -> Option<&'a Pat<'hir>> {
128
- if let PatKind::TupleStruct(pat_path, [inner_pat], _) = pat.kind &&
129
- is_res_lang_ctor(cx, cx.qpath_res(&pat_path, pat.hir_id), OptionSome) &&
130
- !is_refutable(cx, inner_pat) &&
131
- let else_body = peel_blocks(else_body) &&
132
- let ExprKind::Ret(Some(ret_val)) = else_body.kind &&
133
- let ExprKind::Path(ret_path) = ret_val.kind &&
134
- is_res_lang_ctor(cx, cx.qpath_res(&ret_path, ret_val.hir_id), OptionNone)
135
- {
136
- Some(inner_pat)
137
- } else {
138
- None
139
- }
140
- }
141
-
142
98
fn check_let_some_else_return_none(cx: &LateContext<'_>, stmt: &Stmt<'_>) {
143
99
if let StmtKind::Local(Local { pat, init: Some(init_expr), els: Some(els), .. }) = stmt.kind &&
144
100
let Block { stmts: &[], expr: Some(els), .. } = els &&
0 commit comments