@@ -24,6 +24,7 @@ pub struct SpanlessEq<'a, 'tcx> {
24
24
cx : & ' a LateContext < ' tcx > ,
25
25
maybe_typeck_results : Option < & ' tcx TypeckResults < ' tcx > > ,
26
26
allow_side_effects : bool ,
27
+ expr_fallback : Option < Box < dyn Fn ( & Expr < ' _ > , & Expr < ' _ > ) -> bool + ' a > > ,
27
28
}
28
29
29
30
impl < ' a , ' tcx > SpanlessEq < ' a , ' tcx > {
@@ -32,6 +33,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
32
33
cx,
33
34
maybe_typeck_results : cx. maybe_typeck_results ( ) ,
34
35
allow_side_effects : true ,
36
+ expr_fallback : None ,
35
37
}
36
38
}
37
39
@@ -43,6 +45,13 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
43
45
}
44
46
}
45
47
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
+
46
55
/// Checks whether two statements are the same.
47
56
pub fn eq_stmt ( & mut self , left : & Stmt < ' _ > , right : & Stmt < ' _ > ) -> bool {
48
57
match ( & left. kind , & right. kind ) {
@@ -81,7 +90,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
81
90
}
82
91
}
83
92
84
- match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
93
+ let is_eq = match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
85
94
( & ExprKind :: AddrOf ( lb, l_mut, ref le) , & ExprKind :: AddrOf ( rb, r_mut, ref re) ) => {
86
95
lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
87
96
} ,
@@ -158,7 +167,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
158
167
( & ExprKind :: Array ( l) , & ExprKind :: Array ( r) ) => self . eq_exprs ( l, r) ,
159
168
( & ExprKind :: DropTemps ( ref le) , & ExprKind :: DropTemps ( ref re) ) => self . eq_expr ( le, re) ,
160
169
_ => false ,
161
- }
170
+ } ;
171
+ is_eq || self . expr_fallback . as_ref ( ) . map_or ( false , |f| f ( left, right) )
162
172
}
163
173
164
174
fn eq_exprs ( & mut self , left : & [ Expr < ' _ > ] , right : & [ Expr < ' _ > ] ) -> bool {
0 commit comments