Skip to content

Commit 8332fe8

Browse files
committed
Auto merge of rust-lang#5894 - tmiasko:self-assignment, r=Manishearth
Warn about explicit self-assignment Warn about assignments where left-hand side place expression is the same as right-hand side value expression. For example, warn about assignment in: ```rust pub struct Event { id: usize, x: i32, y: i32, } pub fn copy_position(a: &mut Event, b: &Event) { a.x = b.x; a.y = a.y; } ``` changelog: New lint `self_assignment`, checks for explicit self-assignments.
2 parents 8d0d89a + 4f4abf4 commit 8332fe8

17 files changed

+257
-61
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,7 @@ Released 2018-09-13
16901690
[`same_functions_in_if_condition`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_functions_in_if_condition
16911691
[`same_item_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#same_item_push
16921692
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
1693+
[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment
16931694
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
16941695
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse
16951696
[`shadow_same`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_same

clippy_lints/src/assign_ops.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
2+
eq_expr_value, get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method,
33
};
44
use crate::utils::{higher, sugg};
55
use if_chain::if_chain;
@@ -70,11 +70,11 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
7070
return;
7171
}
7272
// lhs op= l op r
73-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, l) {
73+
if eq_expr_value(cx, lhs, l) {
7474
lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, r);
7575
}
7676
// lhs op= l commutative_op r
77-
if is_commutative(op.node) && SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, r) {
77+
if is_commutative(op.node) && eq_expr_value(cx, lhs, r) {
7878
lint_misrefactored_assign_op(cx, expr, *op, rhs, lhs, l);
7979
}
8080
}
@@ -161,14 +161,12 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
161161

162162
if visitor.counter == 1 {
163163
// a = a op b
164-
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, l) {
164+
if eq_expr_value(cx, assignee, l) {
165165
lint(assignee, r);
166166
}
167167
// a = b commutative_op a
168168
// Limited to primitive type as these ops are know to be commutative
169-
if SpanlessEq::new(cx).ignore_fn().eq_expr(assignee, r)
170-
&& cx.typeck_results().expr_ty(assignee).is_primitive_ty()
171-
{
169+
if eq_expr_value(cx, assignee, r) && cx.typeck_results().expr_ty(assignee).is_primitive_ty() {
172170
match op.node {
173171
hir::BinOpKind::Add
174172
| hir::BinOpKind::Mul
@@ -253,7 +251,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ExprVisitor<'a, 'tcx> {
253251
type Map = Map<'tcx>;
254252

255253
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
256-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(self.assignee, expr) {
254+
if eq_expr_value(self.cx, self.assignee, expr) {
257255
self.counter += 1;
258256
}
259257

clippy_lints/src/booleans.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::{
2-
get_trait_def_id, implements_trait, in_macro, is_type_diagnostic_item, paths, snippet_opt, span_lint_and_sugg,
3-
span_lint_and_then, SpanlessEq,
2+
eq_expr_value, get_trait_def_id, implements_trait, in_macro, is_type_diagnostic_item, paths, snippet_opt,
3+
span_lint_and_sugg, span_lint_and_then,
44
};
55
use if_chain::if_chain;
66
use rustc_ast::ast::LitKind;
@@ -128,7 +128,7 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
128128
}
129129
}
130130
for (n, expr) in self.terminals.iter().enumerate() {
131-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e, expr) {
131+
if eq_expr_value(self.cx, e, expr) {
132132
#[allow(clippy::cast_possible_truncation)]
133133
return Ok(Bool::Term(n as u8));
134134
}
@@ -138,8 +138,8 @@ impl<'a, 'tcx, 'v> Hir2Qmm<'a, 'tcx, 'v> {
138138
if implements_ord(self.cx, e_lhs);
139139
if let ExprKind::Binary(expr_binop, expr_lhs, expr_rhs) = &expr.kind;
140140
if negate(e_binop.node) == Some(expr_binop.node);
141-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_lhs, expr_lhs);
142-
if SpanlessEq::new(self.cx).ignore_fn().eq_expr(e_rhs, expr_rhs);
141+
if eq_expr_value(self.cx, e_lhs, expr_lhs);
142+
if eq_expr_value(self.cx, e_rhs, expr_rhs);
143143
then {
144144
#[allow(clippy::cast_possible_truncation)]
145145
return Ok(Bool::Not(Box::new(Bool::Term(n as u8))));

clippy_lints/src/copies.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
use crate::utils::{eq_expr_value, SpanlessEq, SpanlessHash};
12
use crate::utils::{get_parent_expr, higher, if_sequence, snippet, span_lint_and_note, span_lint_and_then};
2-
use crate::utils::{SpanlessEq, SpanlessHash};
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::{Arm, Block, Expr, ExprKind, MatchSource, Pat, PatKind};
55
use rustc_lint::{LateContext, LateLintPass};
@@ -197,8 +197,7 @@ fn lint_same_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
197197
h.finish()
198198
};
199199

200-
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool =
201-
&|&lhs, &rhs| -> bool { SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) };
200+
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool { eq_expr_value(cx, lhs, rhs) };
202201

203202
for (i, j) in search_same(conds, hash, eq) {
204203
span_lint_and_note(
@@ -222,7 +221,7 @@ fn lint_same_fns_in_if_cond(cx: &LateContext<'_>, conds: &[&Expr<'_>]) {
222221

223222
let eq: &dyn Fn(&&Expr<'_>, &&Expr<'_>) -> bool = &|&lhs, &rhs| -> bool {
224223
// Do not spawn warning if `IFS_SAME_COND` already produced it.
225-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs, rhs) {
224+
if eq_expr_value(cx, lhs, rhs) {
226225
return false;
227226
}
228227
SpanlessEq::new(cx).eq_expr(lhs, rhs)

clippy_lints/src/double_comparison.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
77
use rustc_span::source_map::Span;
88

9-
use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
9+
use crate::utils::{eq_expr_value, snippet_with_applicability, span_lint_and_sugg};
1010

1111
declare_clippy_lint! {
1212
/// **What it does:** Checks for double comparisons that could be simplified to a single expression.
@@ -46,8 +46,7 @@ impl<'tcx> DoubleComparisons {
4646
},
4747
_ => return,
4848
};
49-
let mut spanless_eq = SpanlessEq::new(cx).ignore_fn();
50-
if !(spanless_eq.eq_expr(&llhs, &rlhs) && spanless_eq.eq_expr(&lrhs, &rrhs)) {
49+
if !(eq_expr_value(cx, &llhs, &rlhs) && eq_expr_value(cx, &lrhs, &rrhs)) {
5150
return;
5251
}
5352
macro_rules! lint_double_comparison {

clippy_lints/src/eq_op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::{
2-
implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq,
2+
eq_expr_value, implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then,
33
};
44
use rustc_errors::Applicability;
55
use rustc_hir::{BinOp, BinOpKind, BorrowKind, Expr, ExprKind};
@@ -69,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for EqOp {
6969
if macro_with_not_op(&left.kind) || macro_with_not_op(&right.kind) {
7070
return;
7171
}
72-
if is_valid_operator(op) && SpanlessEq::new(cx).ignore_fn().eq_expr(left, right) {
72+
if is_valid_operator(op) && eq_expr_value(cx, left, right) {
7373
span_lint(
7474
cx,
7575
EQ_OP,

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::{
22
constant, constant_simple, Constant,
33
Constant::{Int, F32, F64},
44
};
5-
use crate::utils::{get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg, SpanlessEq};
5+
use crate::utils::{eq_expr_value, get_parent_expr, higher, numeric_literal, span_lint_and_sugg, sugg};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::{BinOpKind, Expr, ExprKind, PathSegment, UnOp};
@@ -363,8 +363,8 @@ fn detect_hypot(cx: &LateContext<'_>, args: &[Expr<'_>]) -> Option<String> {
363363
if_chain! {
364364
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref lmul_lhs, ref lmul_rhs) = add_lhs.kind;
365365
if let ExprKind::Binary(Spanned { node: BinOpKind::Mul, .. }, ref rmul_lhs, ref rmul_rhs) = add_rhs.kind;
366-
if are_exprs_equal(cx, lmul_lhs, lmul_rhs);
367-
if are_exprs_equal(cx, rmul_lhs, rmul_rhs);
366+
if eq_expr_value(cx, lmul_lhs, lmul_rhs);
367+
if eq_expr_value(cx, rmul_lhs, rmul_rhs);
368368
then {
369369
return Some(format!("{}.hypot({})", Sugg::hir(cx, &lmul_lhs, ".."), Sugg::hir(cx, &rmul_lhs, "..")));
370370
}
@@ -502,8 +502,8 @@ fn check_mul_add(cx: &LateContext<'_>, expr: &Expr<'_>) {
502502
fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
503503
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
504504
match op {
505-
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right) && are_exprs_equal(cx, left, test),
506-
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, left) && are_exprs_equal(cx, right, test),
505+
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, right) && eq_expr_value(cx, left, test),
506+
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, left) && eq_expr_value(cx, right, test),
507507
_ => false,
508508
}
509509
} else {
@@ -515,19 +515,15 @@ fn is_testing_positive(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -
515515
fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -> bool {
516516
if let ExprKind::Binary(Spanned { node: op, .. }, left, right) = expr.kind {
517517
match op {
518-
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left) && are_exprs_equal(cx, right, test),
519-
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, right) && are_exprs_equal(cx, left, test),
518+
BinOpKind::Gt | BinOpKind::Ge => is_zero(cx, left) && eq_expr_value(cx, right, test),
519+
BinOpKind::Lt | BinOpKind::Le => is_zero(cx, right) && eq_expr_value(cx, left, test),
520520
_ => false,
521521
}
522522
} else {
523523
false
524524
}
525525
}
526526

527-
fn are_exprs_equal(cx: &LateContext<'_>, expr1: &Expr<'_>, expr2: &Expr<'_>) -> bool {
528-
SpanlessEq::new(cx).ignore_fn().eq_expr(expr1, expr2)
529-
}
530-
531527
/// Returns true iff expr is some zero literal
532528
fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
533529
match constant_simple(cx, cx.typeck_results(), expr) {
@@ -546,12 +542,12 @@ fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
546542
/// returns None.
547543
fn are_negated<'a>(cx: &LateContext<'_>, expr1: &'a Expr<'a>, expr2: &'a Expr<'a>) -> Option<(bool, &'a Expr<'a>)> {
548544
if let ExprKind::Unary(UnOp::UnNeg, expr1_negated) = &expr1.kind {
549-
if are_exprs_equal(cx, expr1_negated, expr2) {
545+
if eq_expr_value(cx, expr1_negated, expr2) {
550546
return Some((false, expr2));
551547
}
552548
}
553549
if let ExprKind::Unary(UnOp::UnNeg, expr2_negated) = &expr2.kind {
554-
if are_exprs_equal(cx, expr1, expr2_negated) {
550+
if eq_expr_value(cx, expr1, expr2_negated) {
555551
return Some((true, expr1));
556552
}
557553
}
@@ -614,7 +610,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>
614610
args_a.len() == args_b.len() &&
615611
(
616612
["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) ||
617-
method_name_a.as_str() == "log" && args_a.len() == 2 && are_exprs_equal(cx, &args_a[1], &args_b[1])
613+
method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1])
618614
);
619615
}
620616
}

clippy_lints/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ mod reference;
284284
mod regex;
285285
mod repeat_once;
286286
mod returns;
287+
mod self_assignment;
287288
mod serde_api;
288289
mod shadow;
289290
mod single_component_path_imports;
@@ -773,6 +774,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
773774
&repeat_once::REPEAT_ONCE,
774775
&returns::LET_AND_RETURN,
775776
&returns::NEEDLESS_RETURN,
777+
&self_assignment::SELF_ASSIGNMENT,
776778
&serde_api::SERDE_API_MISUSE,
777779
&shadow::SHADOW_REUSE,
778780
&shadow::SHADOW_SAME,
@@ -1090,6 +1092,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10901092
store.register_late_pass(|| box pattern_type_mismatch::PatternTypeMismatch);
10911093
store.register_late_pass(|| box stable_sort_primitive::StableSortPrimitive);
10921094
store.register_late_pass(|| box repeat_once::RepeatOnce);
1095+
store.register_late_pass(|| box self_assignment::SelfAssignment);
10931096

10941097
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
10951098
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1421,6 +1424,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14211424
LintId::of(&repeat_once::REPEAT_ONCE),
14221425
LintId::of(&returns::LET_AND_RETURN),
14231426
LintId::of(&returns::NEEDLESS_RETURN),
1427+
LintId::of(&self_assignment::SELF_ASSIGNMENT),
14241428
LintId::of(&serde_api::SERDE_API_MISUSE),
14251429
LintId::of(&single_component_path_imports::SINGLE_COMPONENT_PATH_IMPORTS),
14261430
LintId::of(&slow_vector_initialization::SLOW_VECTOR_INITIALIZATION),
@@ -1714,6 +1718,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17141718
LintId::of(&ptr::MUT_FROM_REF),
17151719
LintId::of(&ranges::REVERSED_EMPTY_RANGES),
17161720
LintId::of(&regex::INVALID_REGEX),
1721+
LintId::of(&self_assignment::SELF_ASSIGNMENT),
17171722
LintId::of(&serde_api::SERDE_API_MISUSE),
17181723
LintId::of(&suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
17191724
LintId::of(&suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),

clippy_lints/src/question_mark.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
77

88
use crate::utils::sugg::Sugg;
99
use crate::utils::{
10-
higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability,
11-
span_lint_and_sugg, SpanlessEq,
10+
eq_expr_value, higher, is_type_diagnostic_item, match_def_path, match_qpath, paths, snippet_with_applicability,
11+
span_lint_and_sugg,
1212
};
1313

1414
declare_clippy_lint! {
@@ -65,7 +65,7 @@ impl QuestionMark {
6565
if let ExprKind::Block(block, None) = &else_.kind;
6666
if block.stmts.is_empty();
6767
if let Some(block_expr) = &block.expr;
68-
if SpanlessEq::new(cx).ignore_fn().eq_expr(subject, block_expr);
68+
if eq_expr_value(cx, subject, block_expr);
6969
then {
7070
replacement = Some(format!("Some({}?)", receiver_str));
7171
}

clippy_lints/src/self_assignment.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use crate::utils::{eq_expr_value, snippet, span_lint};
2+
use rustc_hir::{Expr, ExprKind};
3+
use rustc_lint::{LateContext, LateLintPass};
4+
use rustc_session::{declare_lint_pass, declare_tool_lint};
5+
6+
declare_clippy_lint! {
7+
/// **What it does:** Checks for explicit self-assignments.
8+
///
9+
/// **Why is this bad?** Self-assignments are redundant and unlikely to be
10+
/// intentional.
11+
///
12+
/// **Known problems:** If expression contains any deref coercions or
13+
/// indexing operations they are assumed not to have any side effects.
14+
///
15+
/// **Example:**
16+
///
17+
/// ```rust
18+
/// struct Event {
19+
/// id: usize,
20+
/// x: i32,
21+
/// y: i32,
22+
/// }
23+
///
24+
/// fn copy_position(a: &mut Event, b: &Event) {
25+
/// a.x = b.x;
26+
/// a.y = a.y;
27+
/// }
28+
/// ```
29+
pub SELF_ASSIGNMENT,
30+
correctness,
31+
"explicit self-assignment"
32+
}
33+
34+
declare_lint_pass!(SelfAssignment => [SELF_ASSIGNMENT]);
35+
36+
impl<'tcx> LateLintPass<'tcx> for SelfAssignment {
37+
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
38+
if let ExprKind::Assign(lhs, rhs, _) = &expr.kind {
39+
if eq_expr_value(cx, lhs, rhs) {
40+
let lhs = snippet(cx, lhs.span, "<lhs>");
41+
let rhs = snippet(cx, rhs.span, "<rhs>");
42+
span_lint(
43+
cx,
44+
SELF_ASSIGNMENT,
45+
expr.span,
46+
&format!("self-assignment of `{}` to `{}`", rhs, lhs),
47+
);
48+
}
49+
}
50+
}
51+
}

clippy_lints/src/swap.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::sugg::Sugg;
22
use crate::utils::{
3-
differing_macro_contexts, is_type_diagnostic_item, snippet_with_applicability, span_lint_and_then, walk_ptrs_ty,
4-
SpanlessEq,
3+
differing_macro_contexts, eq_expr_value, is_type_diagnostic_item, snippet_with_applicability, span_lint_and_then,
4+
walk_ptrs_ty,
55
};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
@@ -92,8 +92,8 @@ fn check_manual_swap(cx: &LateContext<'_>, block: &Block<'_>) {
9292
if rhs2.segments.len() == 1;
9393

9494
if ident.as_str() == rhs2.segments[0].ident.as_str();
95-
if SpanlessEq::new(cx).ignore_fn().eq_expr(tmp_init, lhs1);
96-
if SpanlessEq::new(cx).ignore_fn().eq_expr(rhs1, lhs2);
95+
if eq_expr_value(cx, tmp_init, lhs1);
96+
if eq_expr_value(cx, rhs1, lhs2);
9797
then {
9898
if let ExprKind::Field(ref lhs1, _) = lhs1.kind {
9999
if let ExprKind::Field(ref lhs2, _) = lhs2.kind {
@@ -193,7 +193,7 @@ enum Slice<'a> {
193193
fn check_for_slice<'a>(cx: &LateContext<'_>, lhs1: &'a Expr<'_>, lhs2: &'a Expr<'_>) -> Slice<'a> {
194194
if let ExprKind::Index(ref lhs1, ref idx1) = lhs1.kind {
195195
if let ExprKind::Index(ref lhs2, ref idx2) = lhs2.kind {
196-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, lhs2) {
196+
if eq_expr_value(cx, lhs1, lhs2) {
197197
let ty = walk_ptrs_ty(cx.typeck_results().expr_ty(lhs1));
198198

199199
if matches!(ty.kind, ty::Slice(_))
@@ -221,8 +221,8 @@ fn check_suspicious_swap(cx: &LateContext<'_>, block: &Block<'_>) {
221221
if !differing_macro_contexts(first.span, second.span);
222222
if let ExprKind::Assign(ref lhs0, ref rhs0, _) = first.kind;
223223
if let ExprKind::Assign(ref lhs1, ref rhs1, _) = second.kind;
224-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs0, rhs1);
225-
if SpanlessEq::new(cx).ignore_fn().eq_expr(lhs1, rhs0);
224+
if eq_expr_value(cx, lhs0, rhs1);
225+
if eq_expr_value(cx, lhs1, rhs0);
226226
then {
227227
let lhs0 = Sugg::hir_opt(cx, lhs0);
228228
let rhs0 = Sugg::hir_opt(cx, rhs0);

0 commit comments

Comments
 (0)