Skip to content

Commit a49b1fe

Browse files
committed
clean-up
1 parent 34fab5c commit a49b1fe

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5360,7 +5360,7 @@ impl Methods {
53605360
}
53615361
},
53625362
(sym::lock, []) => {
5363-
mut_mutex_lock::check(cx, expr, recv, span);
5363+
mut_mutex_lock::check(cx, recv, span);
53645364
},
53655365
(name @ (sym::map | sym::map_err), [m_arg]) => {
53665366
if name == sym::map {

clippy_lints/src/methods/mut_mutex_lock.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ use rustc_span::{Span, sym};
99

1010
use 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>, recv: &'tcx Expr<'tcx>, name_span: Span) {
1313
if matches!(expr_custom_deref_adjustment(cx, recv), None | Some(Mutability::Mut))
14-
&& 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)
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`
16+
&& let (recv_ty, _, Some(Mutability::Mut)) = peel_and_count_ty_refs(cx.typeck_results().expr_ty(recv))
17+
&& recv_ty.is_diag_item(cx, sym::Mutex)
1818
{
1919
span_lint_and_sugg(
2020
cx,

clippy_utils/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,9 @@ pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, owner: OwnerId) -> Opti
459459
/// This method will return tuple of projection stack and root of the expression,
460460
/// used in `can_mut_borrow_both`.
461461
///
462-
/// For example, if `e` represents the `v[0].a.b[x]`
463-
/// this method will return a tuple, composed of a `Vec`
464-
/// containing the `Expr`s for `v[0], v[0].a, v[0].a.b, v[0].a.b[x]`
465-
/// and an `Expr` for root of them, `v`
462+
/// For example, if `e` represents the `v[0].a.b[x]` this method will return a tuple, composed of:
463+
/// - a `Vec` containing the `Expr`s for `v[0], v[0].a, v[0].a.b, v[0].a.b[x]`
464+
/// - and an `Expr` for root of them, `v`
466465
fn projection_stack<'a, 'hir>(mut e: &'a Expr<'hir>) -> (Vec<&'a Expr<'hir>>, &'a Expr<'hir>) {
467466
let mut result = vec![];
468467
let root = loop {
@@ -488,7 +487,8 @@ pub fn expr_custom_deref_adjustment(cx: &LateContext<'_>, e: &Expr<'_>) -> Optio
488487
Adjust::Deref(None) => None,
489488
_ => Some(None),
490489
})
491-
.and_then(|x| x)
490+
// if there were no adjustments to begin with, trivially none of them are of the custom-deref kind
491+
.unwrap_or(None)
492492
}
493493

494494
/// Checks if two expressions can be mutably borrowed simultaneously

tests/ui/mut_mutex_lock.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(dead_code, unused_mut)]
21
#![warn(clippy::mut_mutex_lock)]
32

43
use std::sync::{Arc, Mutex};

tests/ui/mut_mutex_lock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![allow(dead_code, unused_mut)]
21
#![warn(clippy::mut_mutex_lock)]
32

43
use std::sync::{Arc, Mutex};

tests/ui/mut_mutex_lock.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
2-
--> tests/ui/mut_mutex_lock.rs:10:33
2+
--> tests/ui/mut_mutex_lock.rs:9:33
33
|
44
LL | let mut value = value_mutex.lock().unwrap();
55
| ^^^^ help: change this to: `get_mut`
@@ -8,7 +8,7 @@ LL | let mut value = value_mutex.lock().unwrap();
88
= help: to override `-D warnings` add `#[allow(clippy::mut_mutex_lock)]`
99

1010
error: calling `&mut Mutex::lock` unnecessarily locks an exclusive (mutable) reference
11-
--> tests/ui/mut_mutex_lock.rs:16:43
11+
--> tests/ui/mut_mutex_lock.rs:15:43
1212
|
1313
LL | let mut value = mut_ref_mut_ref_mutex.lock().unwrap();
1414
| ^^^^ help: change this to: `get_mut`

0 commit comments

Comments
 (0)