Skip to content

Commit

Permalink
Inline is_mut_mutex_lock_call
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancisMurillo committed Oct 5, 2020
1 parent bba012d commit 978a2ca
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions clippy_lints/src/mut_mutex_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ declare_lint_pass!(MutMutexLock => [MUT_MUTEX_LOCK]);
impl<'tcx> LateLintPass<'tcx> for MutMutexLock {
fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) {
if_chain! {
if is_mut_mutex_lock_call(cx, ex).is_some();
if let ExprKind::MethodCall(path, _span, args, _) = &ex.kind;
if path.ident.name == sym!(lock);
let ty = cx.typeck_results().expr_ty(&args[0]);
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type));
then {
span_lint_and_help(
cx,
Expand All @@ -58,18 +62,3 @@ impl<'tcx> LateLintPass<'tcx> for MutMutexLock {
}
}
}

fn is_mut_mutex_lock_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if_chain! {
if let ExprKind::MethodCall(path, _span, args, _) = &expr.kind;
if path.ident.name == sym!(lock);
let ty = cx.typeck_results().expr_ty(&args[0]);
if let ty::Ref(_, inner_ty, Mutability::Mut) = ty.kind();
if is_type_diagnostic_item(cx, inner_ty, sym!(mutex_type));
then {
Some(&args[0])
} else {
None
}
}
}

0 comments on commit 978a2ca

Please sign in to comment.