about summary refs log tree commit diff
path: root/clippy_lints/src/operators/self_assignment.rs
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2022-06-30 10:50:09 +0200
committerPhilipp Krones <hello@philkrones.com>2022-06-30 10:50:09 +0200
commit09f5df5087c1d045db3bbf1b886702ec343a2f61 (patch)
tree5f7eecd245841b64223f85e99b269c9dd3b55f18 /clippy_lints/src/operators/self_assignment.rs
parentee37029afa62e93ab5ec8b1f2a23f8dbfd2a453f (diff)
Merge commit '0cb0f7636851f9fcc57085cf80197a2ef6db098f' into clippyup
Diffstat (limited to 'clippy_lints/src/operators/self_assignment.rs')
-rw-r--r--clippy_lints/src/operators/self_assignment.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/clippy_lints/src/operators/self_assignment.rs b/clippy_lints/src/operators/self_assignment.rs
new file mode 100644
index 00000000000..9d6bec05bf0
--- /dev/null
+++ b/clippy_lints/src/operators/self_assignment.rs
@@ -0,0 +1,20 @@
+use clippy_utils::diagnostics::span_lint;
+use clippy_utils::eq_expr_value;
+use clippy_utils::source::snippet;
+use rustc_hir::Expr;
+use rustc_lint::LateContext;
+
+use super::SELF_ASSIGNMENT;
+
+pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>) {
+    if eq_expr_value(cx, lhs, rhs) {
+        let lhs = snippet(cx, lhs.span, "<lhs>");
+        let rhs = snippet(cx, rhs.span, "<rhs>");
+        span_lint(
+            cx,
+            SELF_ASSIGNMENT,
+            e.span,
+            &format!("self-assignment of `{}` to `{}`", rhs, lhs),
+        );
+    }
+}