4aa2a44a55
9962: Add empty-body check to replace_match_with_if_let and re-prioritize choices r=elkowar a=elkowar This PR changes some behaviour of the `replace_match_with_if_let` ide-assist. Concretely, it makes two changes: it introduces a check for empty expression bodies. This means that checks of the shape ```rs match x { A => {} B => { println!("hi"); } } ``` will prefer to use the B branch as the first (and only) variant. It also reprioritizes the importance of "happy" and "sad" patterns. Concretely, if there are reasons to prefer having the sad pattern be the first (/only) pattern, it will follow these. This means that in the case of ```rs match x { Ok(_) => { println!("Success"); } Err(e) => { println!("Failure: {}", e); } } ``` the `Err` variant will correctly be used as the first expression in the generated if. Up until now, the generated code was actually invalid, as it would generate ```rs if let Ok(_) = x { println!("Success"); } else { println!("Failure: {}", e); } ``` where `e` in the else branch is not defined. Co-authored-by: elkowar <5300871+elkowar@users.noreply.github.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |