Skip to content

Commit 9b800b1

Browse files
committed
Rename SpanlessEq::ignore_fn to deny_side_effects
No functional changes intended.
1 parent 6afa4ef commit 9b800b1

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

clippy_lints/src/utils/hir_utils.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ pub struct SpanlessEq<'a, 'tcx> {
2323
/// Context used to evaluate constant expressions.
2424
cx: &'a LateContext<'tcx>,
2525
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,
2927
}
3028

3129
impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
3230
pub fn new(cx: &'a LateContext<'tcx>) -> Self {
3331
Self {
3432
cx,
3533
maybe_typeck_results: cx.maybe_typeck_results(),
36-
ignore_fn: false,
34+
allow_side_effects: true,
3735
}
3836
}
3937

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 {
4140
Self {
42-
ignore_fn: true,
41+
allow_side_effects: false,
4342
..self
4443
}
4544
}
@@ -67,7 +66,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
6766

6867
#[allow(clippy::similar_names)]
6968
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) {
7170
return false;
7271
}
7372

@@ -108,7 +107,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
108107
},
109108
(&ExprKind::Box(ref l), &ExprKind::Box(ref r)) => self.eq_expr(l, r),
110109
(&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)
112111
},
113112
(&ExprKind::Cast(ref lx, ref lt), &ExprKind::Cast(ref rx, ref rt))
114113
| (&ExprKind::Type(ref lx, ref lt), &ExprKind::Type(ref rx, ref rt)) => {
@@ -134,7 +133,7 @@ impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {
134133
})
135134
},
136135
(&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)
138137
},
139138
(&ExprKind::Repeat(ref le, ref ll_id), &ExprKind::Repeat(ref re, ref rl_id)) => {
140139
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) -
342341

343342
/// Checks if two expressions evaluate to the same value, and don't contain any side effects.
344343
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)
346345
}
347346

348347
/// Type used to hash an ast element. This is different from the `Hash` trait

clippy_lints/src/utils/internal_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleCalls {
492492
if let StmtKind::Semi(only_expr) = &stmts[0].kind;
493493
if let ExprKind::MethodCall(ref ps, _, ref span_call_args, _) = &only_expr.kind;
494494
let and_then_snippets = get_and_then_snippets(cx, and_then_args);
495-
let mut sle = SpanlessEq::new(cx).ignore_fn();
495+
let mut sle = SpanlessEq::new(cx).deny_side_effects();
496496
then {
497497
match &*ps.ident.as_str() {
498498
"span_suggestion" if sle.eq_expr(&and_then_args[2], &span_call_args[1]) => {

0 commit comments

Comments
 (0)