Closed
Description
Summary
We had our pipelines failing due to clippy::readonly_write_lock
We use read write locks, and maybe we are using it in a wrong way
Lint Name
readonly_write_lock
Reproducer
I tried this code with @sigilioso:
pub struct MyStruct {
[...]
rw_lock: RwLock<()>,
}
[...]
impl MyStruct{
fn get() -> bool
{
let _read_guard = self.rw_lock.read().unwrap();
[...]
// reading data from filesystem
}
fn put() -> bool
{
let _write_guard = self.rw_lock.write().unwrap();
[...]
// writing data from filesystem
}
I saw this happen:
(help: consider using a read lock instead: `self.rw_lock.read())
I do not expect any error, since we are using the rw_lock
not to lock a specific piece of data, but a piece of code through _read_guard/_write_guard
.
For this reason having a lock as RwLock<()>
would always provide a similar error, since there is nothing to write
Version
rustc 1.79.0-beta.1 (6b544f5ff 2024-04-28)
Additional Labels
No response