Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix let_undescore_lock false-positive when binding without locking #8990

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions clippy_lints/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ declare_clippy_lint! {

declare_lint_pass!(LetUnderscore => [LET_UNDERSCORE_MUST_USE, LET_UNDERSCORE_LOCK, LET_UNDERSCORE_DROP]);

const SYNC_GUARD_PATHS: [&[&str]; 5] = [
const SYNC_GUARD_PATHS: [&[&str]; 6] = [
&paths::MUTEX_GUARD,
&paths::RWLOCK_READ_GUARD,
&paths::RWLOCK_WRITE_GUARD,
&paths::PARKING_LOT_RAWMUTEX,
&paths::PARKING_LOT_RAWRWLOCK,
&paths::PARKING_LOT_MUTEX_GUARD,
&paths::PARKING_LOT_RWLOCK_READ_GUARD,
&paths::PARKING_LOT_RWLOCK_WRITE_GUARD,
];

impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
Expand Down
2 changes: 0 additions & 2 deletions clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ pub const OPTION_SOME: [&str; 4] = ["core", "option", "Option", "Some"];
pub const ORD: [&str; 3] = ["core", "cmp", "Ord"];
pub const OS_STRING_AS_OS_STR: [&str; 5] = ["std", "ffi", "os_str", "OsString", "as_os_str"];
pub const OS_STR_TO_OS_STRING: [&str; 5] = ["std", "ffi", "os_str", "OsStr", "to_os_string"];
pub const PARKING_LOT_RAWMUTEX: [&str; 3] = ["parking_lot", "raw_mutex", "RawMutex"];
pub const PARKING_LOT_RAWRWLOCK: [&str; 3] = ["parking_lot", "raw_rwlock", "RawRwLock"];
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/let_underscore_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ fn main() {
let _ = rw.try_read();
let _ = rw.try_write();

// These shouldn't throw an error.
let _ = m;
let _ = rw;

use parking_lot::{lock_api::RawMutex, Mutex, RwLock};

let p_m: Mutex<()> = Mutex::const_new(RawMutex::INIT, ());
Expand All @@ -24,4 +28,9 @@ fn main() {
let p_rw = RwLock::new(0);
let _ = p_rw.read();
let _ = p_rw.write();

// These shouldn't throw an error.
let _ = p_m;
let _ = p_m1;
let _ = p_rw;
}
8 changes: 4 additions & 4 deletions tests/ui/let_underscore_lock.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ LL | let _ = rw.try_write();
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`

error: non-binding let on a synchronization lock
--> $DIR/let_underscore_lock.rs:19:5
--> $DIR/let_underscore_lock.rs:23:5
|
LL | let _ = p_m.lock();
| ^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`

error: non-binding let on a synchronization lock
--> $DIR/let_underscore_lock.rs:22:5
--> $DIR/let_underscore_lock.rs:26:5
|
LL | let _ = p_m1.lock();
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`

error: non-binding let on a synchronization lock
--> $DIR/let_underscore_lock.rs:25:5
--> $DIR/let_underscore_lock.rs:29:5
|
LL | let _ = p_rw.read();
| ^^^^^^^^^^^^^^^^^^^^
|
= help: consider using an underscore-prefixed named binding or dropping explicitly with `std::mem::drop`

error: non-binding let on a synchronization lock
--> $DIR/let_underscore_lock.rs:26:5
--> $DIR/let_underscore_lock.rs:30:5
|
LL | let _ = p_rw.write();
| ^^^^^^^^^^^^^^^^^^^^^
Expand Down