Consider this example of using a tokio watch channel. Clippy suggests to collapse the nested if blocks into this form.
Following clippy's suggestion leads to a dead-lock. This is because watch::Sender::borrow() locks the sender untils its return value goes out of scope. Having two separate if blocks, the lock is released before calling watch::Sender::send() and everything is fine. Having both calls in one statement means one scope, so the lock is still there and blocks the second call.
Consider this example of using a tokio watch channel. Clippy suggests to collapse the nested
ifblocks into this form.Following clippy's suggestion leads to a dead-lock. This is because
watch::Sender::borrow()locks the sender untils its return value goes out of scope. Having two separateifblocks, the lock is released before callingwatch::Sender::send()and everything is fine. Having both calls in one statement means one scope, so the lock is still there and blocks the second call.