@@ -24,6 +24,7 @@ pub struct SpanlessEq<'a, 'tcx> {
2424 cx : & ' a LateContext < ' tcx > ,
2525 maybe_typeck_results : Option < & ' tcx TypeckResults < ' tcx > > ,
2626 allow_side_effects : bool ,
27+ expr_fallback : Option < Box < dyn Fn ( & Expr < ' _ > , & Expr < ' _ > ) -> bool + ' a > > ,
2728}
2829
2930impl < ' a , ' tcx > SpanlessEq < ' a , ' tcx > {
@@ -32,6 +33,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
3233 cx,
3334 maybe_typeck_results : cx. maybe_typeck_results ( ) ,
3435 allow_side_effects : true ,
36+ expr_fallback : None ,
3537 }
3638 }
3739
@@ -43,6 +45,13 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
4345 }
4446 }
4547
48+ pub fn expr_fallback ( self , expr_fallback : impl Fn ( & Expr < ' _ > , & Expr < ' _ > ) -> bool + ' a ) -> Self {
49+ Self {
50+ expr_fallback : Some ( Box :: new ( expr_fallback) ) ,
51+ ..self
52+ }
53+ }
54+
4655 /// Checks whether two statements are the same.
4756 pub fn eq_stmt ( & mut self , left : & Stmt < ' _ > , right : & Stmt < ' _ > ) -> bool {
4857 match ( & left. kind , & right. kind ) {
@@ -81,7 +90,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
8190 }
8291 }
8392
84- match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
93+ let is_eq = match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
8594 ( & ExprKind :: AddrOf ( lb, l_mut, ref le) , & ExprKind :: AddrOf ( rb, r_mut, ref re) ) => {
8695 lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
8796 } ,
@@ -158,7 +167,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
158167 ( & ExprKind :: Array ( l) , & ExprKind :: Array ( r) ) => self . eq_exprs ( l, r) ,
159168 ( & ExprKind :: DropTemps ( ref le) , & ExprKind :: DropTemps ( ref re) ) => self . eq_expr ( le, re) ,
160169 _ => false ,
161- }
170+ } ;
171+ is_eq || self . expr_fallback . as_ref ( ) . map_or ( false , |f| f ( left, right) )
162172 }
163173
164174 fn eq_exprs ( & mut self , left : & [ Expr < ' _ > ] , right : & [ Expr < ' _ > ] ) -> bool {
0 commit comments