@@ -247,7 +247,7 @@ impl HirEqInterExpr<'_, '_, '_> {
247
247
res
248
248
}
249
249
250
- #[ expect( clippy:: similar_names) ]
250
+ #[ expect( clippy:: similar_names, clippy :: too_many_lines ) ]
251
251
pub fn eq_expr ( & mut self , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> bool {
252
252
if !self . check_ctxt ( left. span . ctxt ( ) , right. span . ctxt ( ) ) {
253
253
return false ;
@@ -271,9 +271,7 @@ impl HirEqInterExpr<'_, '_, '_> {
271
271
( & ExprKind :: AddrOf ( lb, l_mut, le) , & ExprKind :: AddrOf ( rb, r_mut, re) ) => {
272
272
lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
273
273
} ,
274
- ( & ExprKind :: Continue ( li) , & ExprKind :: Continue ( ri) ) => {
275
- both ( & li. label , & ri. label , |l, r| l. ident . name == r. ident . name )
276
- } ,
274
+ ( & ExprKind :: Array ( l) , & ExprKind :: Array ( r) ) => self . eq_exprs ( l, r) ,
277
275
( & ExprKind :: Assign ( ll, lr, _) , & ExprKind :: Assign ( rl, rr, _) ) => {
278
276
self . inner . allow_side_effects && self . eq_expr ( ll, rl) && self . eq_expr ( lr, rr)
279
277
} ,
@@ -294,9 +292,15 @@ impl HirEqInterExpr<'_, '_, '_> {
294
292
( & ExprKind :: Call ( l_fun, l_args) , & ExprKind :: Call ( r_fun, r_args) ) => {
295
293
self . inner . allow_side_effects && self . eq_expr ( l_fun, r_fun) && self . eq_exprs ( l_args, r_args)
296
294
} ,
297
- ( & ExprKind :: Cast ( lx, lt) , & ExprKind :: Cast ( rx, rt) ) | ( & ExprKind :: Type ( lx , lt ) , & ExprKind :: Type ( rx , rt ) ) => {
295
+ ( & ExprKind :: Cast ( lx, lt) , & ExprKind :: Cast ( rx, rt) ) => {
298
296
self . eq_expr ( lx, rx) && self . eq_ty ( lt, rt)
299
297
} ,
298
+ ( & ExprKind :: Closure ( _l) , & ExprKind :: Closure ( _r) ) => false ,
299
+ ( & ExprKind :: ConstBlock ( lb) , & ExprKind :: ConstBlock ( rb) ) => self . eq_body ( lb. body , rb. body ) ,
300
+ ( & ExprKind :: Continue ( li) , & ExprKind :: Continue ( ri) ) => {
301
+ both ( & li. label , & ri. label , |l, r| l. ident . name == r. ident . name )
302
+ } ,
303
+ ( & ExprKind :: DropTemps ( le) , & ExprKind :: DropTemps ( re) ) => self . eq_expr ( le, re) ,
300
304
( & ExprKind :: Field ( l_f_exp, ref l_f_ident) , & ExprKind :: Field ( r_f_exp, ref r_f_ident) ) => {
301
305
l_f_ident. name == r_f_ident. name && self . eq_expr ( l_f_exp, r_f_exp)
302
306
} ,
@@ -329,24 +333,70 @@ impl HirEqInterExpr<'_, '_, '_> {
329
333
&& self . eq_expr ( l_receiver, r_receiver)
330
334
&& self . eq_exprs ( l_args, r_args)
331
335
} ,
336
+ ( & ExprKind :: OffsetOf ( l_container, l_fields) , & ExprKind :: OffsetOf ( r_container, r_fields) ) => {
337
+ self . eq_ty ( l_container, r_container) && over ( l_fields, r_fields, |l, r| l. name == r. name )
338
+ } ,
339
+ ( ExprKind :: Path ( l) , ExprKind :: Path ( r) ) => self . eq_qpath ( l, r) ,
332
340
( & ExprKind :: Repeat ( le, ll) , & ExprKind :: Repeat ( re, rl) ) => {
333
341
self . eq_expr ( le, re) && self . eq_array_length ( ll, rl)
334
342
} ,
335
343
( ExprKind :: Ret ( l) , ExprKind :: Ret ( r) ) => both ( l, r, |l, r| self . eq_expr ( l, r) ) ,
336
- ( ExprKind :: Path ( l) , ExprKind :: Path ( r) ) => self . eq_qpath ( l, r) ,
337
344
( & ExprKind :: Struct ( l_path, lf, ref lo) , & ExprKind :: Struct ( r_path, rf, ref ro) ) => {
338
345
self . eq_qpath ( l_path, r_path)
339
346
&& both ( lo, ro, |l, r| self . eq_expr ( l, r) )
340
347
&& over ( lf, rf, |l, r| self . eq_expr_field ( l, r) )
341
348
} ,
342
349
( & ExprKind :: Tup ( l_tup) , & ExprKind :: Tup ( r_tup) ) => self . eq_exprs ( l_tup, r_tup) ,
350
+ ( & ExprKind :: Type ( le, lt) , & ExprKind :: Type ( re, rt) ) => self . eq_expr ( le, re) && self . eq_ty ( lt, rt) ,
343
351
( & ExprKind :: Unary ( l_op, le) , & ExprKind :: Unary ( r_op, re) ) => l_op == r_op && self . eq_expr ( le, re) ,
344
- ( & ExprKind :: Array ( l) , & ExprKind :: Array ( r) ) => self . eq_exprs ( l, r) ,
345
- ( & ExprKind :: DropTemps ( le) , & ExprKind :: DropTemps ( re) ) => self . eq_expr ( le, re) ,
346
- ( & ExprKind :: OffsetOf ( l_container, l_fields) , & ExprKind :: OffsetOf ( r_container, r_fields) ) => {
347
- self . eq_ty ( l_container, r_container) && over ( l_fields, r_fields, |l, r| l. name == r. name )
348
- } ,
349
- _ => false ,
352
+ ( & ExprKind :: Yield ( le, _) , & ExprKind :: Yield ( re, _) ) => return self . eq_expr ( le, re) ,
353
+ (
354
+ // Else branches for branches above, grouped as per `match_same_arms`.
355
+ | & ExprKind :: AddrOf ( ..)
356
+ | & ExprKind :: Array ( ..)
357
+ | & ExprKind :: Assign ( ..)
358
+ | & ExprKind :: AssignOp ( ..)
359
+ | & ExprKind :: Binary ( ..)
360
+ | & ExprKind :: Become ( ..)
361
+ | & ExprKind :: Block ( ..)
362
+ | & ExprKind :: Break ( ..)
363
+ | & ExprKind :: Call ( ..)
364
+ | & ExprKind :: Cast ( ..)
365
+ | & ExprKind :: ConstBlock ( ..)
366
+ | & ExprKind :: Continue ( ..)
367
+ | & ExprKind :: DropTemps ( ..)
368
+ | & ExprKind :: Field ( ..)
369
+ | & ExprKind :: Index ( ..)
370
+ | & ExprKind :: If ( ..)
371
+ | & ExprKind :: Let ( ..)
372
+ | & ExprKind :: Lit ( ..)
373
+ | & ExprKind :: Loop ( ..)
374
+ | & ExprKind :: Match ( ..)
375
+ | & ExprKind :: MethodCall ( ..)
376
+ | & ExprKind :: OffsetOf ( ..)
377
+ | & ExprKind :: Path ( ..)
378
+ | & ExprKind :: Repeat ( ..)
379
+ | & ExprKind :: Ret ( ..)
380
+ | & ExprKind :: Struct ( ..)
381
+ | & ExprKind :: Tup ( ..)
382
+ | & ExprKind :: Type ( ..)
383
+ | & ExprKind :: Unary ( ..)
384
+ | & ExprKind :: Yield ( ..)
385
+
386
+ // --- Special cases that do not have a positive branch.
387
+
388
+ // `Err` represents an invalid expression, so let's never assume that
389
+ // an invalid expressions is equal to anything.
390
+ | & ExprKind :: Err ( ..)
391
+
392
+ // For the time being, we always consider that two closures are unequal.
393
+ // This behavior may change in the future.
394
+ | & ExprKind :: Closure ( ..)
395
+ // For the time being, we always consider that two instances of InlineAsm are different.
396
+ // This behavior may change in the future.
397
+ | & ExprKind :: InlineAsm ( _)
398
+ , _
399
+ ) => false ,
350
400
} ;
351
401
( is_eq && ( !self . should_ignore ( left) || !self . should_ignore ( right) ) )
352
402
|| self . inner . expr_fallback . as_mut ( ) . map_or ( false , |f| f ( left, right) )
@@ -684,6 +734,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
684
734
self . hash_name ( i. ident . name ) ;
685
735
}
686
736
} ,
737
+ ExprKind :: Array ( v) => {
738
+ self . hash_exprs ( v) ;
739
+ } ,
687
740
ExprKind :: Assign ( l, r, _) => {
688
741
self . hash_expr ( l) ;
689
742
self . hash_expr ( r) ;
@@ -693,6 +746,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
693
746
self . hash_expr ( l) ;
694
747
self . hash_expr ( r) ;
695
748
} ,
749
+ ExprKind :: Become ( f) => {
750
+ self . hash_expr ( f) ;
751
+ } ,
696
752
ExprKind :: Block ( b, _) => {
697
753
self . hash_block ( b) ;
698
754
} ,
@@ -709,9 +765,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
709
765
self . hash_expr ( j) ;
710
766
}
711
767
} ,
712
- ExprKind :: DropTemps ( e) | ExprKind :: Yield ( e, _) => {
713
- self . hash_expr ( e) ;
714
- } ,
715
768
ExprKind :: Call ( fun, args) => {
716
769
self . hash_expr ( fun) ;
717
770
self . hash_exprs ( args) ;
@@ -727,6 +780,12 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
727
780
// closures inherit TypeckResults
728
781
self . hash_expr ( self . cx . tcx . hir ( ) . body ( body) . value ) ;
729
782
} ,
783
+ ExprKind :: ConstBlock ( ref l_id) => {
784
+ self . hash_body ( l_id. body ) ;
785
+ } ,
786
+ ExprKind :: DropTemps ( e) | ExprKind :: Yield ( e, _) => {
787
+ self . hash_expr ( e) ;
788
+ } ,
730
789
ExprKind :: Field ( e, ref f) => {
731
790
self . hash_expr ( e) ;
732
791
self . hash_name ( f. name ) ;
@@ -788,20 +847,13 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
788
847
}
789
848
}
790
849
} ,
791
- ExprKind :: OffsetOf ( container, fields) => {
792
- self . hash_ty ( container) ;
793
- for field in fields {
794
- self . hash_name ( field. name ) ;
795
- }
796
- } ,
797
850
ExprKind :: Let ( Let { pat, init, ty, .. } ) => {
798
851
self . hash_expr ( init) ;
799
852
if let Some ( ty) = ty {
800
853
self . hash_ty ( ty) ;
801
854
}
802
855
self . hash_pat ( pat) ;
803
856
} ,
804
- ExprKind :: Err ( _) => { } ,
805
857
ExprKind :: Lit ( l) => {
806
858
l. node . hash ( & mut self . s ) ;
807
859
} ,
@@ -836,8 +888,14 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
836
888
self . hash_expr ( receiver) ;
837
889
self . hash_exprs ( args) ;
838
890
} ,
839
- ExprKind :: ConstBlock ( ref l_id) => {
840
- self . hash_body ( l_id. body ) ;
891
+ ExprKind :: OffsetOf ( container, fields) => {
892
+ self . hash_ty ( container) ;
893
+ for field in fields {
894
+ self . hash_name ( field. name ) ;
895
+ }
896
+ } ,
897
+ ExprKind :: Path ( ref qpath) => {
898
+ self . hash_qpath ( qpath) ;
841
899
} ,
842
900
ExprKind :: Repeat ( e, len) => {
843
901
self . hash_expr ( e) ;
@@ -848,12 +906,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
848
906
self . hash_expr ( e) ;
849
907
}
850
908
} ,
851
- ExprKind :: Become ( f) => {
852
- self . hash_expr ( f) ;
853
- } ,
854
- ExprKind :: Path ( ref qpath) => {
855
- self . hash_qpath ( qpath) ;
856
- } ,
857
909
ExprKind :: Struct ( path, fields, ref expr) => {
858
910
self . hash_qpath ( path) ;
859
911
@@ -869,13 +921,11 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
869
921
ExprKind :: Tup ( tup) => {
870
922
self . hash_exprs ( tup) ;
871
923
} ,
872
- ExprKind :: Array ( v) => {
873
- self . hash_exprs ( v) ;
874
- } ,
875
924
ExprKind :: Unary ( lop, le) => {
876
925
std:: mem:: discriminant ( & lop) . hash ( & mut self . s ) ;
877
926
self . hash_expr ( le) ;
878
927
} ,
928
+ ExprKind :: Err ( _) => { } ,
879
929
}
880
930
}
881
931
0 commit comments