rust-analyzer/crates
bors[bot] 4aa2a44a55
Merge #9962
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>
2021-08-21 10:12:17 +00:00
..
base_db feat: include full path in the cyclic deps error 2021-08-18 15:35:04 +03:00
cfg internal: remove useless helpers 2021-08-09 15:58:21 +03:00
flycheck internal: a bit more of cwd safety for flycheck 2021-07-17 18:13:35 +03:00
hir Use correct HirFileId in find_related_test 2021-08-20 13:50:40 +02:00
hir_def Do not replace items annotated with builtin attrs with the attr input 2021-08-20 13:50:06 +02:00
hir_expand internal: prep to 2021 edition 2021-08-20 16:20:18 +03:00
hir_ty feat: type inference for if-let guards 2021-08-14 00:09:30 +02:00
ide Use correct HirFileId in find_related_test 2021-08-20 13:50:40 +02:00
ide_assists Merge #9962 2021-08-21 10:12:17 +00:00
ide_completion Merge #9902 2021-08-14 17:43:52 +00:00
ide_db Rename fails on renaming definitions created by macros 2021-08-20 00:12:47 +02:00
ide_diagnostics Merge #9810 2021-08-08 10:35:00 +00:00
ide_ssr fix: avoid pathological macro expansions 2021-08-09 16:15:02 +03:00
limit internal: add API to check what are the max limits in practice 2021-07-31 18:26:43 +03:00
mbe internal: remove dead code 2021-08-14 20:29:46 +03:00
parser Support if let match guards 2021-08-13 00:25:14 +02:00
paths Fix AbsPath::ends_with 2021-07-18 10:25:14 +03:00
proc_macro_api Fix formatting 2021-08-17 19:25:37 +03:00
proc_macro_srv Copy the proc_macro crate for the 1.56 ABI 2021-08-07 16:34:59 +01:00
proc_macro_test cargo_metadata 0.14 2021-07-09 11:01:55 -04:00
profile internal: make non-zero times stand out in profile 2021-07-31 16:22:03 +03:00
project_model fix: resolve core::arch module 2021-08-20 17:01:27 +03:00
rust-analyzer internal: prep to 2021 edition 2021-08-20 16:20:18 +03:00
sourcegen minor: make sure that project_root works correctly 2021-07-13 15:02:29 +03:00
stdx Remove proc macro management thread 2021-07-08 16:43:39 +02:00
syntax minor: move functionality to a better place 2021-08-14 20:43:28 +03:00
test_utils Show type actions on ranged type hover 2021-08-11 13:52:57 +02:00
text_edit Handle all rename special cases for all record pattern fields 2021-08-16 22:48:38 +02:00
toolchain minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
tt minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
vfs internal: document that ascription is preferred to a turbo fish 2021-08-11 14:16:15 +03:00
vfs-notify Bump notify version to 5.0.0-pre.12 2021-08-17 17:25:11 +02:00