mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
parent
f7e2cb4470
commit
6a73a45418
@ -129,7 +129,7 @@ fn is_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Opt
|
||||
if_chain! {
|
||||
if let ExprKind::MethodCall(path, [self_arg, ..], _) = &expr.kind;
|
||||
if path.ident.as_str() == "lock";
|
||||
let ty = cx.typeck_results().expr_ty(self_arg);
|
||||
let ty = cx.typeck_results().expr_ty(self_arg).peel_refs();
|
||||
if is_type_diagnostic_item(cx, ty, sym::Mutex);
|
||||
then {
|
||||
Some(self_arg)
|
||||
|
@ -39,4 +39,12 @@ fn if_let_different_mutex() {
|
||||
};
|
||||
}
|
||||
|
||||
fn mutex_ref(mutex: &Mutex<i32>) {
|
||||
if let Ok(i) = mutex.lock() {
|
||||
do_stuff(i);
|
||||
} else {
|
||||
let _x = mutex.lock();
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -25,5 +25,17 @@ LL | | };
|
||||
|
|
||||
= help: move the lock call outside of the `if let ...` expression
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock
|
||||
--> $DIR/if_let_mutex.rs:43:5
|
||||
|
|
||||
LL | / if let Ok(i) = mutex.lock() {
|
||||
LL | | do_stuff(i);
|
||||
LL | | } else {
|
||||
LL | | let _x = mutex.lock();
|
||||
LL | | };
|
||||
| |_____^
|
||||
|
|
||||
= help: move the lock call outside of the `if let ...` expression
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user