about summary refs log tree commit diff
path: root/tests/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-12-12 13:52:49 +0000
committerbors <bors@rust-lang.org>2022-12-12 13:52:49 +0000
commit3a7215b92ee23d8e4399ff713381416fb4886bcc (patch)
tree9054aa9af8d20e58f1dba39bd1310089e7a90939 /tests/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs
parent16c70fe69bafa60827a087a8dc48fbf2f56261d2 (diff)
parent57fb18e3bdc44e0ec390ec48b501f85bb78218e8 (diff)
downloadrust-3a7215b92ee23d8e4399ff713381416fb4886bcc.tar.gz
rust-3a7215b92ee23d8e4399ff713381416fb4886bcc.zip
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.
Diffstat (limited to 'tests/codegen/src-hash-algorithm/src-hash-algorithm-sha1.rs')
0 files changed, 0 insertions, 0 deletions