Skip to content

Commit 77ec0f0

Browse files
committed
WIP: don't lint statics
1 parent e6755c5 commit 77ec0f0

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

clippy_lints/src/methods/mut_mutex_lock.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,22 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, recv: &'tcx Expr<'tcx>, name_s
7373
// that the field type is not a `&T`, and we'll do that in the next iteration of the
7474
// loop, during adjustment checking
7575
ExprKind::Field(base, _) => r = base,
76-
// No more projections to check
77-
_ => break,
76+
// We arrived at the innermost receiver
77+
_ => {
78+
if let ExprKind::Path(ref p) = r.kind
79+
&& cx
80+
.qpath_res(p, r.hir_id)
81+
.opt_def_id()
82+
.and_then(|id| cx.tcx.static_mutability(id))
83+
== Some(Mutability::Not)
84+
{
85+
// The mutex is stored in a `static`, and we don't want to suggest making that
86+
// mutable
87+
return;
88+
}
89+
// No more projections to check
90+
break;
91+
},
7892
}
7993
}
8094

tests/ui/mut_mutex_lock.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ fn mut_ref_ref_mutex_lock() {
3737
*guard += 1;
3838
}
3939

40+
static MTX: Mutex<i32> = Mutex::new(0);
41+
42+
fn dont_suggest_on_statics() {
43+
MTX.lock().unwrap();
44+
}
45+
4046
mod issue16253 {
4147
use std::sync::{Arc, Mutex};
4248

0 commit comments

Comments
 (0)