1
1
#![ allow( clippy:: wildcard_imports, clippy:: enum_glob_use) ]
2
2
3
- use clippy_utils:: ast_utils:: { eq_field_pat, eq_id, eq_pat, eq_path} ;
3
+ use clippy_utils:: ast_utils:: { eq_field_pat, eq_id, eq_maybe_qself , eq_pat, eq_path} ;
4
4
use clippy_utils:: diagnostics:: span_lint_and_then;
5
5
use clippy_utils:: { meets_msrv, msrvs, over} ;
6
6
use rustc_ast:: mut_visit:: * ;
@@ -273,16 +273,17 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize)
273
273
|k| always_pat ! ( k, Tuple ( ps) => ps) ,
274
274
) ,
275
275
// Transform `S(pre, x, post) | ... | S(pre, y, post)` into `S(pre, x | y, post)`.
276
- TupleStruct ( path1, ps1) => extend_with_matching_product (
276
+ TupleStruct ( qself1 , path1, ps1) => extend_with_matching_product (
277
277
ps1, start, alternatives,
278
278
|k, ps1, idx| matches ! (
279
279
k,
280
- TupleStruct ( path2, ps2) if eq_path( path1, path2) && eq_pre_post( ps1, ps2, idx)
280
+ TupleStruct ( qself2, path2, ps2)
281
+ if eq_maybe_qself( qself1, qself2) && eq_path( path1, path2) && eq_pre_post( ps1, ps2, idx)
281
282
) ,
282
- |k| always_pat ! ( k, TupleStruct ( _, ps) => ps) ,
283
+ |k| always_pat ! ( k, TupleStruct ( _, _ , ps) => ps) ,
283
284
) ,
284
285
// Transform a record pattern `S { fp_0, ..., fp_n }`.
285
- Struct ( path1, fps1, rest1) => extend_with_struct_pat ( path1, fps1, * rest1, start, alternatives) ,
286
+ Struct ( qself1 , path1, fps1, rest1) => extend_with_struct_pat ( qself1 , path1, fps1, * rest1, start, alternatives) ,
286
287
} ;
287
288
288
289
alternatives[ focus_idx] . kind = focus_kind;
@@ -294,6 +295,7 @@ fn transform_with_focus_on_idx(alternatives: &mut Vec<P<Pat>>, focus_idx: usize)
294
295
/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern
295
296
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
296
297
fn extend_with_struct_pat (
298
+ qself1 : & Option < ast:: QSelf > ,
297
299
path1 : & ast:: Path ,
298
300
fps1 : & mut Vec < ast:: PatField > ,
299
301
rest1 : bool ,
@@ -306,8 +308,9 @@ fn extend_with_struct_pat(
306
308
start,
307
309
alternatives,
308
310
|k| {
309
- matches ! ( k, Struct ( path2, fps2, rest2)
311
+ matches ! ( k, Struct ( qself2 , path2, fps2, rest2)
310
312
if rest1 == * rest2 // If one struct pattern has `..` so must the other.
313
+ && eq_maybe_qself( qself1, qself2)
311
314
&& eq_path( path1, path2)
312
315
&& fps1. len( ) == fps2. len( )
313
316
&& fps1. iter( ) . enumerate( ) . all( |( idx_1, fp1) | {
@@ -323,7 +326,7 @@ fn extend_with_struct_pat(
323
326
} ) )
324
327
} ,
325
328
// Extract `p2_k`.
326
- |k| always_pat ! ( k, Struct ( _, mut fps, _) => fps. swap_remove( pos_in_2. take( ) . unwrap( ) ) . pat) ,
329
+ |k| always_pat ! ( k, Struct ( _, _ , mut fps, _) => fps. swap_remove( pos_in_2. take( ) . unwrap( ) ) . pat) ,
327
330
) ;
328
331
extend_with_tail_or ( & mut fps1[ idx] . pat , tail_or)
329
332
} )
0 commit comments