]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/if_let_mutex.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / if_let_mutex.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::if_let_mutex)]
2
3use std::ops::Deref;
4use std::sync::Mutex;
5
6fn do_stuff<T>(_: T) {}
7
8fn if_let() {
9 let m = Mutex::new(1_u8);
10 if let Err(locked) = m.lock() {
11 do_stuff(locked);
12 } else {
13 let lock = m.lock().unwrap();
14 do_stuff(lock);
15 };
16}
17
18// This is the most common case as the above case is pretty
19// contrived.
20fn if_let_option() {
21 let m = Mutex::new(Some(0_u8));
22 if let Some(locked) = m.lock().unwrap().deref() {
23 do_stuff(locked);
24 } else {
25 let lock = m.lock().unwrap();
26 do_stuff(lock);
27 };
28}
29
30// When mutexs are different don't warn
31fn if_let_different_mutex() {
32 let m = Mutex::new(Some(0_u8));
33 let other = Mutex::new(None::<u8>);
34 if let Some(locked) = m.lock().unwrap().deref() {
35 do_stuff(locked);
36 } else {
37 let lock = other.lock().unwrap();
38 do_stuff(lock);
39 };
40}
41
42fn main() {}