11use clippy_utils:: diagnostics:: span_lint_and_sugg;
22use clippy_utils:: expr_custom_deref_adjustment;
3- use clippy_utils:: res:: MaybeDef ;
3+ use clippy_utils:: res:: { MaybeDef , MaybeTypeckRes } ;
44use clippy_utils:: ty:: peel_and_count_ty_refs;
55use rustc_errors:: Applicability ;
66use rustc_hir:: { Expr , Mutability } ;
@@ -9,12 +9,12 @@ use rustc_span::{Span, sym};
99
1010use super :: MUT_MUTEX_LOCK ;
1111
12- pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , ex : & ' tcx Expr < ' tcx > , recv : & ' tcx Expr < ' tcx > , name_span : Span ) {
12+ pub ( super ) fn check < ' tcx > ( cx : & LateContext < ' tcx > , expr : & ' tcx Expr < ' tcx > , recv : & ' tcx Expr < ' tcx > , name_span : Span ) {
1313 if matches ! ( expr_custom_deref_adjustment( cx, recv) , None | Some ( Mutability :: Mut ) )
14+ // NOTE: the reason we don't use `expr_ty_adjusted` here is that a call to `Mutex::lock` by itself
15+ // adjusts the receiver to be `&Mutex`
1416 && let ( _, _, Some ( Mutability :: Mut ) ) = peel_and_count_ty_refs ( cx. typeck_results ( ) . expr_ty ( recv) )
15- && let Some ( method_id) = cx. typeck_results ( ) . type_dependent_def_id ( ex. hir_id )
16- && let Some ( impl_id) = cx. tcx . impl_of_assoc ( method_id)
17- && cx. tcx . type_of ( impl_id) . is_diag_item ( cx, sym:: Mutex )
17+ && cx. ty_based_def ( expr) . opt_parent ( cx) . is_diag_item ( cx, sym:: Mutex )
1818 {
1919 span_lint_and_sugg (
2020 cx,
0 commit comments