rust-analyzer/crates
bors 3a7215b92e Auto merge of #13732 - rami3l:fix/gen-partial-eq, r=jonas-schievink
fix: add fallback case in generated `PartialEq` impl

Partially fixes #13727.

When generating `PartialEq` implementations for enums, the original code can already generate the following fallback case:

```rs
_ => std::mem::discriminant(self) == std::mem::discriminant(other),
```

However, it has been suppressed in the following example for no good reason:

```rs
enum Either<T, U> {
    Left(T),
    Right(U),
}

impl<T, U> PartialEq for Either<T, U> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Left(l0), Self::Left(r0)) => l0 == r0,
            (Self::Right(l0), Self::Right(r0)) => l0 == r0,
            // _ => std::mem::discriminant(self) == std::mem::discriminant(other),
            // ^ this completes the match arms!
        }
    }
}
```

This PR has removed that suppression logic.

~~Of course, the PR could have suppressed the fallback case generation for single-variant enums instead, but I believe that this case is quite rare and should be caught by `#[warn(unreachable_patterns)]` anyway.~~

After this fix, when the enum has >1 variants, the following fallback arm will be generated :

* `_ => false,` if we've already gone through every case where the variants of `self` and `other` match;
* The original one (as stated above) in other cases.

---

Note: The code example is still wrong after the fix due to incorrect trait bounds.
2022-12-12 13:52:49 +00:00
..
base-db ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
cfg ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
flycheck Properly implement Drop for JodGroupChild 2022-11-24 21:30:15 +01:00
hir Make assoc_resolutions always have a Substitution 2022-12-10 17:05:33 +01:00
hir-def Auto merge of #13490 - HKalbasi:layout, r=jonas-schievink 2022-12-07 15:22:03 +00:00
hir-expand Compute data layout of types 2022-12-04 00:29:34 +03:30
hir-ty Make assoc_resolutions always have a Substitution 2022-12-10 17:05:33 +01:00
ide Auto merge of #13725 - bvanjoi:resolve-const-triat-impls, r=flodiebold 2022-12-10 13:58:28 +00:00
ide-assists Auto merge of #13732 - rami3l:fix/gen-partial-eq, r=jonas-schievink 2022-12-12 13:52:49 +00:00
ide-completion Auto merge of #13611 - yue4u:fix/completion-after-colon, r=yue4u 2022-11-26 17:55:00 +00:00
ide-db Encode the variants of HirFileId in a u32 with MSB as the tag 2022-11-25 23:28:35 +01:00
ide-diagnostics ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
ide-ssr ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
limit ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
mbe ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
parser Fix parsing of _ = x in closure body 2022-12-12 12:57:29 +01:00
paths ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
proc-macro-api ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
proc-macro-srv Handle raw identifiers in proc macro server 2022-12-04 00:26:05 +09:00
proc-macro-srv-cli ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
proc-macro-test ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
profile ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
project-model Auto merge of #13667 - Veykril:detached-files-sysroot, r=Veykril 2022-11-24 09:21:44 +00:00
rust-analyzer Version the inlay hint resolve data 2022-11-29 19:20:32 +01:00
sourcegen ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
stdx ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
syntax Move precedence handling to crates/syntax 2022-12-08 18:46:30 +00:00
test-utils Auto merge of #13490 - HKalbasi:layout, r=jonas-schievink 2022-12-07 15:22:03 +00:00
text-edit ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
toolchain ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
tt Handle raw identifiers in proc macro server 2022-12-04 00:26:05 +09:00
vfs ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00
vfs-notify ⬆️ rust-analyzer 2022-11-23 17:24:03 +02:00