2 Check for temporaries returned from function calls in a match scrutinee that have the
3 `clippy::has_significant_drop` attribute.
6 The `clippy::has_significant_drop` attribute can be added to types whose Drop impls have
7 an important side-effect, such as unlocking a mutex, making it important for users to be
8 able to accurately understand their lifetimes. When a temporary is returned in a function
9 call in a match scrutinee, its lifetime lasts until the end of the match block, which may
12 For `Mutex`es this can lead to a deadlock. This happens when the match scrutinee uses a
13 function call that returns a `MutexGuard` and then tries to lock again in one of the match
14 arms. In that case the `MutexGuard` in the scrutinee will not be dropped until the end of
15 the match block and thus will not unlock.
19 let mutex = Mutex::new(State {});
21 match mutex.lock().unwrap().foo() {
23 mutex.lock().unwrap().bar(); // Deadlock!
28 println!("All done!");
32 let mutex = Mutex::new(State {});
34 let is_foo = mutex.lock().unwrap().foo();
37 mutex.lock().unwrap().bar();
42 println!("All done!");