mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
834b691a9f
Emit `if_let_mutex` in presence of other mutexes Currently (master, not nightly nor stable) `if_let_mutex` does not emit a warning here: ```rs let m1 = Mutex::new(10); let m2 = Mutex::new(()); if let 100..=200 = *m1.lock().unwrap() { m2.lock(); } else { m1.lock(); } ``` It currently looks for the first call to `.lock()` on *any* mutex receiver inside of the if/else body, and only later (outside of the visitor) checks that the receiver matches the mutex in the scrutinee. That means that in cases like the above, it finds the `m2.lock()` expression, stops the visitor, fails the check that it's the same mutex (`m2` != `m1`) and then does not look for any other `.lock()` calls. So, just make the receiver check also part of the visitor so that we only stop the visitor when we also find the right receiver. The first commit has the actual changes described here. The sceond one just unnests all the `if let`s ---- changelog: none |
||
---|---|---|
.. | ||
test_utils | ||
ui | ||
ui-cargo | ||
ui-internal | ||
ui-toml | ||
workspace_test | ||
check-fmt.rs | ||
clippy.toml | ||
compile-test.rs | ||
dogfood.rs | ||
headers.rs | ||
integration.rs | ||
lint_message_convention.rs | ||
missing-test-files.rs | ||
versioncheck.rs | ||
workspace.rs |