]> git.lizzy.rs Git - rust.git/commitdiff
Inline is_mut_mutex_lock_call
authorFrancis Murillo <francis.murillo@protonmail.com>
Mon, 5 Oct 2020 03:44:54 +0000 (11:44 +0800)
committerFrancis Murillo <francis.murillo@protonmail.com>
Sun, 25 Oct 2020 09:41:30 +0000 (17:41 +0800)
clippy_lints/src/mut_mutex_lock.rs

index 0680e578537c6a18ea9361ebbe5d883d9ddfc4cf..ca3371a5d75c2a17a1b4ee48a1c12a55762e7b78 100644 (file)
 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 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, ex: &'tcx Expr<'tcx>) {
         }
     }
 }
-
-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
-        }
-    }
-}