Finds nested match expressions where the patterns may be combined to reduce the number of branches.
Apply with the Grit CLI
grit apply collapsible_match
Combines nested match
BEFORE
fn func(opt: Option<Result<u64, String>>) { let n = match opt { Some(n) => match n { Ok(n) => n, Err => return, } None => return, }; }
AFTER
fn func(opt: Option<Result<u64, String>>) { let n = match opt { Some(Ok(n)) => n, _ => return, }; }
Does not combine arms with different expressions
RUST
fn func(opt: Option<Result<u64, String>>) { let n = match opt { Some(n) => match n { Ok(n) => n, Err => 5, } None => return, }; }