What it does
Warns the user when they create a write lock on an RwLock, but only use it to read data.
Sometimes, after a code change, some particular location in a codebase that used to mutate data starts using it as read-only. If the programmer forgets to change the lock type, everything will still compile without warnings, but the code will run slower than it could, and potentially create deadlocks.
Lint Name
readonly-write-lock
Category
perf
Advantage
- Prevent unnecessarily blocking other threads
Drawbacks
No response
Example
let x = std::sync::RwLock::new(5.0f64);
let x_write = x.write().unwrap();
println!("{}", x_write);
Could be written as:
let x = std::sync::RwLock::new(5.0f64);
let x_read = x.read().unwrap();
println!("{}", x_read);
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c28b43e7d0b36f1c85f708c8e0b9bd0e
What it does
Warns the user when they create a write lock on an
RwLock, but only use it to read data.Sometimes, after a code change, some particular location in a codebase that used to mutate data starts using it as read-only. If the programmer forgets to change the lock type, everything will still compile without warnings, but the code will run slower than it could, and potentially create deadlocks.
Lint Name
readonly-write-lock
Category
perf
Advantage
Drawbacks
No response
Example
Could be written as:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c28b43e7d0b36f1c85f708c8e0b9bd0e