about summary refs log tree commit diff
path: root/src/docs/branches_sharing_code.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/branches_sharing_code.txt
parent854f751b263dfac06dc3f635f8a9f92b8bc51da6 (diff)
downloadrust-98bf99e2f8cf8b357d63a67ce67d5fc5ceef8b3c.tar.gz
rust-98bf99e2f8cf8b357d63a67ce67d5fc5ceef8b3c.zip
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
Diffstat (limited to 'src/docs/branches_sharing_code.txt')
-rw-r--r--src/docs/branches_sharing_code.txt32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/docs/branches_sharing_code.txt b/src/docs/branches_sharing_code.txt
new file mode 100644
index 00000000000..79be6124798
--- /dev/null
+++ b/src/docs/branches_sharing_code.txt
@@ -0,0 +1,32 @@
+### What it does
+Checks if the `if` and `else` block contain shared code that can be
+moved out of the blocks.
+
+### Why is this bad?
+Duplicate code is less maintainable.
+
+### Known problems
+* The lint doesn't check if the moved expressions modify values that are being used in
+  the if condition. The suggestion can in that case modify the behavior of the program.
+  See [rust-clippy#7452](https://github.com/rust-lang/rust-clippy/issues/7452)
+
+### Example
+```
+let foo = if … {
+    println!("Hello World");
+    13
+} else {
+    println!("Hello World");
+    42
+};
+```
+
+Use instead:
+```
+println!("Hello World");
+let foo = if … {
+    13
+} else {
+    42
+};
+```
\ No newline at end of file