@@ -23,23 +23,22 @@ pub struct SpanlessEq<'a, 'tcx> {
23
23
/// Context used to evaluate constant expressions.
24
24
cx : & ' a LateContext < ' tcx > ,
25
25
maybe_typeck_results : Option < & ' tcx TypeckResults < ' tcx > > ,
26
- /// If is true, never consider as equal expressions containing function
27
- /// calls.
28
- ignore_fn : bool ,
26
+ allow_side_effects : bool ,
29
27
}
30
28
31
29
impl < ' a , ' tcx > SpanlessEq < ' a , ' tcx > {
32
30
pub fn new ( cx : & ' a LateContext < ' tcx > ) -> Self {
33
31
Self {
34
32
cx,
35
33
maybe_typeck_results : cx. maybe_typeck_results ( ) ,
36
- ignore_fn : false ,
34
+ allow_side_effects : true ,
37
35
}
38
36
}
39
37
40
- pub fn ignore_fn ( self ) -> Self {
38
+ /// Consider expressions containing potential side effects as not equal.
39
+ pub fn deny_side_effects ( self ) -> Self {
41
40
Self {
42
- ignore_fn : true ,
41
+ allow_side_effects : false ,
43
42
..self
44
43
}
45
44
}
@@ -67,7 +66,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
67
66
68
67
#[ allow( clippy:: similar_names) ]
69
68
pub fn eq_expr ( & mut self , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> bool {
70
- if self . ignore_fn && differing_macro_contexts ( left. span , right. span ) {
69
+ if ! self . allow_side_effects && differing_macro_contexts ( left. span , right. span ) {
71
70
return false ;
72
71
}
73
72
@@ -108,7 +107,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
108
107
} ,
109
108
( & ExprKind :: Box ( ref l) , & ExprKind :: Box ( ref r) ) => self . eq_expr ( l, r) ,
110
109
( & ExprKind :: Call ( l_fun, l_args) , & ExprKind :: Call ( r_fun, r_args) ) => {
111
- ! self . ignore_fn && self . eq_expr ( l_fun, r_fun) && self . eq_exprs ( l_args, r_args)
110
+ self . allow_side_effects && self . eq_expr ( l_fun, r_fun) && self . eq_exprs ( l_args, r_args)
112
111
} ,
113
112
( & ExprKind :: Cast ( ref lx, ref lt) , & ExprKind :: Cast ( ref rx, ref rt) )
114
113
| ( & ExprKind :: Type ( ref lx, ref lt) , & ExprKind :: Type ( ref rx, ref rt) ) => {
@@ -134,7 +133,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
134
133
} )
135
134
} ,
136
135
( & ExprKind :: MethodCall ( l_path, _, l_args, _) , & ExprKind :: MethodCall ( r_path, _, r_args, _) ) => {
137
- ! self . ignore_fn && self . eq_path_segment ( l_path, r_path) && self . eq_exprs ( l_args, r_args)
136
+ self . allow_side_effects && self . eq_path_segment ( l_path, r_path) && self . eq_exprs ( l_args, r_args)
138
137
} ,
139
138
( & ExprKind :: Repeat ( ref le, ref ll_id) , & ExprKind :: Repeat ( ref re, ref rl_id) ) => {
140
139
let mut celcx = constant_context ( self . cx , self . cx . tcx . typeck_body ( ll_id. body ) ) ;
@@ -342,7 +341,7 @@ pub fn over<X>(left: &[X], right: &[X], mut eq_fn: impl FnMut(&X, &X) -> bool) -
342
341
343
342
/// Checks if two expressions evaluate to the same value, and don't contain any side effects.
344
343
pub fn eq_expr_value ( cx : & LateContext < ' _ > , left : & Expr < ' _ > , right : & Expr < ' _ > ) -> bool {
345
- SpanlessEq :: new ( cx) . ignore_fn ( ) . eq_expr ( left, right)
344
+ SpanlessEq :: new ( cx) . deny_side_effects ( ) . eq_expr ( left, right)
346
345
}
347
346
348
347
/// Type used to hash an ast element. This is different from the `Hash` trait
0 commit comments