about summary refs log tree commit diff
path: root/src/docs/assign_op_pattern.txt
diff options
context:
space:
mode:
authorPhilipp Krones <hello@philkrones.com>2022-09-09 13:36:26 +0200
committerPhilipp Krones <hello@philkrones.com>2022-09-09 13:36:26 +0200
commit98bf99e2f8cf8b357d63a67ce67d5fc5ceef8b3c (patch)
tree9737ff22b257f29282e7538d9ecb264451a3c1c0 /src/docs/assign_op_pattern.txt
parent854f751b263dfac06dc3f635f8a9f92b8bc51da6 (diff)
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
Diffstat (limited to 'src/docs/assign_op_pattern.txt')
-rw-r--r--src/docs/assign_op_pattern.txt28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/docs/assign_op_pattern.txt b/src/docs/assign_op_pattern.txt
new file mode 100644
index 00000000000..f355c0cc18d
--- /dev/null
+++ b/src/docs/assign_op_pattern.txt
@@ -0,0 +1,28 @@
+### What it does
+Checks for `a = a op b` or `a = b commutative_op a`
+patterns.
+
+### Why is this bad?
+These can be written as the shorter `a op= b`.
+
+### Known problems
+While forbidden by the spec, `OpAssign` traits may have
+implementations that differ from the regular `Op` impl.
+
+### Example
+```
+let mut a = 5;
+let b = 0;
+// ...
+
+a = a + b;
+```
+
+Use instead:
+```
+let mut a = 5;
+let b = 0;
+// ...
+
+a += b;
+```
\ No newline at end of file