Open
Description
What it does
Suggests to replace two assignments in if/then with one.
This too comes from code I've found in the wild, that here I've reduced.
Advantage
DRYer code. Possibly a bit shorter code.
Drawbacks
If done well I think there are no drawbacks.
Example
#![warn(clippy::all)]
#![warn(clippy::nursery)]
#![warn(clippy::pedantic)]
pub const fn foo1(a: &mut u32, b: bool) {
if b {
*a = 1;
} else {
*a = 2;
}
}
fn main() {}
Could be written as:
pub const fn foo2(a: &mut u32, b: bool) {
*a = if b { 1 } else { 2 };
}