diff options
| author | Francis Murillo <francis.murillo@protonmail.com> | 2020-10-05 11:44:54 +0800 |
|---|---|---|
| committer | Francis Murillo <francis.murillo@protonmail.com> | 2020-10-25 17:41:30 +0800 |
| commit | 77e34a69bbbec0ef05dee9750ff3e7db4eb35d59 (patch) | |
| tree | 99ebbfe2064cbfd36a2b3ef4cc71e7d522988162 | |
| parent | ec0c3afa7303383ee039c252b59b56023052ae2e (diff) | |
| download | rust-77e34a69bbbec0ef05dee9750ff3e7db4eb35d59.tar.gz rust-77e34a69bbbec0ef05dee9750ff3e7db4eb35d59.zip | |
Inline is_mut_mutex_lock_call
| -rw-r--r-- | clippy_lints/src/mut_mutex_lock.rs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/clippy_lints/src/mut_mutex_lock.rs b/clippy_lints/src/mut_mutex_lock.rs index 0680e578537..ca3371a5d75 100644 --- a/clippy_lints/src/mut_mutex_lock.rs +++ b/clippy_lints/src/mut_mutex_lock.rs @@ -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, @@ -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 - } - } -} |
