summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/if_let_mutex.txt
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools/clippy/src/docs/if_let_mutex.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/tools/clippy/src/docs/if_let_mutex.txt b/src/tools/clippy/src/docs/if_let_mutex.txt
new file mode 100644
index 000000000..4d873ade9
--- /dev/null
+++ b/src/tools/clippy/src/docs/if_let_mutex.txt
@@ -0,0 +1,25 @@
+### What it does
+Checks for `Mutex::lock` calls in `if let` expression
+with lock calls in any of the else blocks.
+
+### Why is this bad?
+The Mutex lock remains held for the whole
+`if let ... else` block and deadlocks.
+
+### Example
+```
+if let Ok(thing) = mutex.lock() {
+ do_thing();
+} else {
+ mutex.lock();
+}
+```
+Should be written
+```
+let locked = mutex.lock();
+if let Ok(thing) = locked {
+ do_thing(thing);
+} else {
+ use_locked(locked);
+}
+``` \ No newline at end of file