rust/tests/ui/deriving
bors 9f82651a5f Auto merge of #103659 - clubby789:improve-partialord-derive, r=nagisa
Special-case deriving `PartialOrd` for enums with dataless variants

I was able to get slightly better codegen by flipping the derived `PartialOrd` logic for two-variant enums.  I also tried to document the implementation of the derive macro to make the special-case logic a little clearer.
```rs
#[derive(PartialEq, PartialOrd)]
pub enum A<T> {
    A,
    B(T)
}
```
```diff
impl<T: ::core::cmp::PartialOrd> ::core::cmp::PartialOrd for A<T> {
   #[inline]
   fn partial_cmp(
       &self,
       other: &A<T>,
   ) -> ::core::option::Option<::core::cmp::Ordering> {
       let __self_tag = ::core::intrinsics::discriminant_value(self);
       let __arg1_tag = ::core::intrinsics::discriminant_value(other);
-      match ::core::cmp::PartialOrd::partial_cmp(&__self_tag, &__arg1_tag) {
-          ::core::option::Option::Some(::core::cmp::Ordering::Equal) => {
-              match (self, other) {
-                  (A::B(__self_0), A::B(__arg1_0)) => {
-                      ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
-                  }
-                  _ => ::core::option::Option::Some(::core::cmp::Ordering::Equal),
-              }
+      match (self, other) {
+          (A::B(__self_0), A::B(__arg1_0)) => {
+              ::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0)
           }
-          cmp => cmp,
+          _ => ::core::cmp::PartialOrd::partial_cmp(&__self_tag, &__arg1_tag),
       }
   }
}
```
Godbolt: [Current](https://godbolt.org/z/GYjEzG1T8), [New](https://godbolt.org/z/GoK78qx15)
I'm not sure how common a case comparing two enums like this (such as `Option`) is, and if it's worth the slowdown of adding a special case to the derive. If it causes overall regressions it might be worth just manually implementing this for `Option`.
2023-01-28 22:11:11 +00:00
..
auxiliary Move /src/test to /tests 2023-01-11 09:32:08 +00:00
derive-no-std.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
derive-partialord-correctness.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-all-codegen.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-all-codegen.stdout Auto merge of #103659 - clubby789:improve-partialord-derive, r=nagisa 2023-01-28 22:11:11 +00:00
deriving-associated-types.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-bounds.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-array.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-generic-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-generic-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-generic-tuple-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-clone-tuple-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-cmp-generic-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-cmp-generic-struct-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-cmp-generic-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-cmp-generic-tuple-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-cmp-shortcircuit.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-copyclone.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-default-box.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-default-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-enum-single-variant.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-eq-ord-boxed-slice.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-hash.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-in-fn.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-in-macro.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-meta-multiple.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-meta.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-self-lifetime-totalord-totaleq.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-show-2.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-show.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-c-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-hash-enum.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-hash-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-struct-empty.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-struct-like-enum-variant.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-struct-tuple.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-struct.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-via-extension-type-params.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-with-helper.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
deriving-with-repr-packed.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-3935.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-6341.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-19358.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-58319.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-89188-gat-hrtb.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-103157.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-103157.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-105101.rs Move /src/test to /tests 2023-01-11 09:32:08 +00:00
issue-105101.stderr Move /src/test to /tests 2023-01-11 09:32:08 +00:00