inline a bunch of if let
s into a single let chain
This commit is contained in:
parent
1a1c978f8e
commit
61dcf6cfe0
@ -51,32 +51,28 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
|
|||||||
if_else: Some(if_else),
|
if_else: Some(if_else),
|
||||||
..
|
..
|
||||||
}) = higher::IfLet::hir(cx, expr)
|
}) = higher::IfLet::hir(cx, expr)
|
||||||
|
&& let Some(op_mutex) = for_each_expr_without_closures(let_expr, |e| mutex_lock_call(cx, e, None))
|
||||||
|
&& let Some(arm_mutex) =
|
||||||
|
for_each_expr_without_closures((if_then, if_else), |e| mutex_lock_call(cx, e, Some(op_mutex)))
|
||||||
{
|
{
|
||||||
let op_mutex = for_each_expr_without_closures(let_expr, |e| mutex_lock_call(cx, e, None));
|
let diag = |diag: &mut Diag<'_, ()>| {
|
||||||
if let Some(op_mutex) = op_mutex {
|
diag.span_label(
|
||||||
let arm_mutex =
|
op_mutex.span,
|
||||||
for_each_expr_without_closures((if_then, if_else), |e| mutex_lock_call(cx, e, Some(op_mutex)));
|
"this Mutex will remain locked for the entire `if let`-block...",
|
||||||
if let Some(arm_mutex) = arm_mutex {
|
);
|
||||||
let diag = |diag: &mut Diag<'_, ()>| {
|
diag.span_label(
|
||||||
diag.span_label(
|
arm_mutex.span,
|
||||||
op_mutex.span,
|
"... and is tried to lock again here, which will always deadlock.",
|
||||||
"this Mutex will remain locked for the entire `if let`-block...",
|
);
|
||||||
);
|
diag.help("move the lock call outside of the `if let ...` expression");
|
||||||
diag.span_label(
|
};
|
||||||
arm_mutex.span,
|
span_lint_and_then(
|
||||||
"... and is tried to lock again here, which will always deadlock.",
|
cx,
|
||||||
);
|
IF_LET_MUTEX,
|
||||||
diag.help("move the lock call outside of the `if let ...` expression");
|
expr.span,
|
||||||
};
|
"calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock",
|
||||||
span_lint_and_then(
|
diag,
|
||||||
cx,
|
);
|
||||||
IF_LET_MUTEX,
|
|
||||||
expr.span,
|
|
||||||
"calling `Mutex::lock` inside the scope of another `Mutex::lock` causes a deadlock",
|
|
||||||
diag,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user