@@ -26,6 +26,7 @@ pub struct SpanlessEq<'a, 'tcx> {
26
26
cx : & ' a LateContext < ' tcx > ,
27
27
maybe_typeck_results : Cell < Option < & ' tcx TypeckResults < ' tcx > > > ,
28
28
allow_side_effects : bool ,
29
+ expr_fallback : Option < Box < dyn Fn ( & Expr < ' _ > , & Expr < ' _ > ) -> bool + ' a > > ,
29
30
}
30
31
31
32
impl < ' a , ' tcx > SpanlessEq < ' a , ' tcx > {
@@ -34,6 +35,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
34
35
cx,
35
36
maybe_typeck_results : Cell :: new ( cx. maybe_typeck_results ( ) ) ,
36
37
allow_side_effects : true ,
38
+ expr_fallback : None ,
37
39
}
38
40
}
39
41
@@ -45,6 +47,13 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
45
47
}
46
48
}
47
49
50
+ pub fn expr_fallback ( self , expr_fallback : impl Fn ( & Expr < ' _ > , & Expr < ' _ > ) -> bool + ' a ) -> Self {
51
+ Self {
52
+ expr_fallback : Some ( Box :: new ( expr_fallback) ) ,
53
+ ..self
54
+ }
55
+ }
56
+
48
57
/// Checks whether two statements are the same.
49
58
pub fn eq_stmt ( & self , left : & Stmt < ' _ > , right : & Stmt < ' _ > ) -> bool {
50
59
match ( & left. kind , & right. kind ) {
@@ -82,7 +91,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
82
91
}
83
92
}
84
93
85
- match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
94
+ let is_eq = match ( & reduce_exprkind ( & left. kind ) , & reduce_exprkind ( & right. kind ) ) {
86
95
( & ExprKind :: AddrOf ( lb, l_mut, ref le) , & ExprKind :: AddrOf ( rb, r_mut, ref re) ) => {
87
96
lb == rb && l_mut == r_mut && self . eq_expr ( le, re)
88
97
} ,
@@ -156,7 +165,8 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
156
165
( & ExprKind :: Array ( l) , & ExprKind :: Array ( r) ) => self . eq_exprs ( l, r) ,
157
166
( & ExprKind :: DropTemps ( ref le) , & ExprKind :: DropTemps ( ref re) ) => self . eq_expr ( le, re) ,
158
167
_ => false ,
159
- }
168
+ } ;
169
+ is_eq || self . expr_fallback . as_ref ( ) . map_or ( false , |f| f ( left, right) )
160
170
}
161
171
162
172
fn eq_exprs ( & self , left : & [ Expr < ' _ > ] , right : & [ Expr < ' _ > ] ) -> bool {
0 commit comments