Skip to content

Commit 77e34a6

Browse files
Inline is_mut_mutex_lock_call
1 parent ec0c3af commit 77e34a6

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

clippy_lints/src/mut_mutex_lock.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ declare_lint_pass!(MutMutexLock => [MUT_MUTEX_LOCK]);
4444
impl<'tcx> LateLintPass<'tcx> for MutMutexLock {
4545
fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) {
4646
if_chain! {
47-
if is_mut_mutex_lock_call(cx, ex).is_some();
47+
if let ExprKind::MethodCall(path, _span, args, _) = &ex.kind;
48+
if path.ident.name == sym!(lock);
49+
let ty = cx.typeck_results().expr_ty(&args[0]);
50+
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
51+
if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type));
4852
then {
4953
span_lint_and_help(
5054
cx,
@@ -58,18 +62,3 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock {
5862
}
5963
}
6064
}
61-
62-
fn is_mut_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
63-
if_chain! {
64-
if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind;
65-
if path.ident.name == sym!(lock);
66-
let ty = cx.typeck_results().expr_ty(&args[0]);
67-
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
68-
if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type));
69-
then {
70-
Some(&args[0])
71-
} else {
72-
None
73-
}
74-
}
75-
}

0 commit comments

Comments
 (0)