@@ -3,12 +3,12 @@ use clippy_utils::diagnostics::span_lint_and_sugg;
3
3
use clippy_utils:: source:: snippet_with_applicability;
4
4
use clippy_utils:: ty:: { is_type_diagnostic_item, same_type_and_consts} ;
5
5
use clippy_utils:: {
6
- eq_expr_value, get_parent_expr_for_hir, get_parent_node, higher, is_else_clause, is_lang_ctor,
6
+ eq_expr_value, get_parent_expr_for_hir, get_parent_node, higher, is_else_clause, is_lang_ctor, over ,
7
7
peel_blocks_with_stmt,
8
8
} ;
9
9
use rustc_errors:: Applicability ;
10
10
use rustc_hir:: LangItem :: OptionNone ;
11
- use rustc_hir:: { Arm , BindingAnnotation , Expr , ExprKind , FnRetTy , Node , Pat , PatKind , Path , PathSegment , QPath } ;
11
+ use rustc_hir:: { Arm , BindingAnnotation , Expr , ExprKind , FnRetTy , Node , Pat , PatKind , Path , QPath } ;
12
12
use rustc_lint:: LateContext ;
13
13
use rustc_span:: sym;
14
14
use rustc_typeck:: hir_ty_to_ty;
@@ -157,8 +157,9 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
157
157
// Example: `Some(val) => Some(val)`
158
158
( PatKind :: TupleStruct ( QPath :: Resolved ( _, path) , tuple_params, _) , ExprKind :: Call ( call_expr, call_params) ) => {
159
159
if let ExprKind :: Path ( QPath :: Resolved ( _, call_path) ) = call_expr. kind {
160
- return same_segments ( path. segments , call_path. segments )
161
- && same_non_ref_symbols ( tuple_params, call_params) ;
160
+ return over ( path. segments , call_path. segments , |pat_seg, call_seg| {
161
+ pat_seg. ident . name == call_seg. ident . name
162
+ } ) && same_non_ref_symbols ( tuple_params, call_params) ;
162
163
}
163
164
} ,
164
165
// Example: `val => val`
@@ -177,7 +178,9 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
177
178
} ,
178
179
// Example: `Custom::TypeA => Custom::TypeB`, or `None => None`
179
180
( PatKind :: Path ( QPath :: Resolved ( _, p_path) ) , ExprKind :: Path ( QPath :: Resolved ( _, e_path) ) ) => {
180
- return same_segments ( p_path. segments , e_path. segments ) ;
181
+ return over ( p_path. segments , e_path. segments , |p_seg, e_seg| {
182
+ p_seg. ident . name == e_seg. ident . name
183
+ } ) ;
181
184
} ,
182
185
// Example: `5 => 5`
183
186
( PatKind :: Lit ( pat_lit_expr) , ExprKind :: Lit ( expr_spanned) ) => {
@@ -191,20 +194,6 @@ fn pat_same_as_expr(pat: &Pat<'_>, expr: &Expr<'_>) -> bool {
191
194
false
192
195
}
193
196
194
- fn same_segments ( left_segs : & [ PathSegment < ' _ > ] , right_segs : & [ PathSegment < ' _ > ] ) -> bool {
195
- if left_segs. len ( ) != right_segs. len ( ) {
196
- return false ;
197
- }
198
-
199
- for i in 0 ..left_segs. len ( ) {
200
- if left_segs[ i] . ident . name != right_segs[ i] . ident . name {
201
- return false ;
202
- }
203
- }
204
-
205
- true
206
- }
207
-
208
197
fn same_non_ref_symbols ( pats : & [ Pat < ' _ > ] , exprs : & [ Expr < ' _ > ] ) -> bool {
209
198
if pats. len ( ) != exprs. len ( ) {
210
199
return false ;
0 commit comments