Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More derive output improvements #98758

Merged
merged 7 commits into from
Jul 8, 2022

Commits on Jul 4, 2022

  1. Add a union to the deriving-all-codegen.rs test.

    Because `derive(Clone)` on unions triggers special behaviour.
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    9d38c45 View commit details
    Browse the repository at this point in the history
  2. Add 0-variant and 1-variant enums to the deriving-all-codegen.rs test.

    Because they are interesting cases with their own code generation paths.
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    d4ecc4f View commit details
    Browse the repository at this point in the history
  3. Avoid unnecessary blocks in derive output.

    By not committing to either block form or expression form until
    necessary, we can avoid lots of unnecessary blocks.
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    5762d23 View commit details
    Browse the repository at this point in the history
  4. Don't repeat AssertParamIs{Clone,Eq} assertions.

    It's common to see repeated assertions like this in derived `clone` and
    `eq` methods:
    ```
    let _: ::core::clone::AssertParamIsClone<u32>;
    let _: ::core::clone::AssertParamIsClone<u32>;
    ```
    This commit avoids them.
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    a7b1d31 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2c911dc View commit details
    Browse the repository at this point in the history
  6. Avoid the unnecessary innermost match in partial_cmp/cmp.

    We currently do a match on the comparison of every field in a struct or
    enum variant. But the last field has a degenerate match like this:
    ```
    match ::core::cmp::Ord::cmp(&self.y, &other.y) {
        ::core::cmp::Ordering::Equal =>
    	::core::cmp::Ordering::Equal,
        cmp => cmp,
    },
    ```
    This commit changes it to this:
    ```
    ::core::cmp::Ord::cmp(&self.y, &other.y),
    ```
    This is fairly straightforward thanks to the existing `cs_fold1`
    function.
    
    The commit also removes the `cs_fold` function which is no longer used.
    
    (Note: there is some repetition now in `cs_cmp` and `cs_partial_cmp`. I
    will remove that in a follow-up PR.)
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    0ee79f2 View commit details
    Browse the repository at this point in the history
  7. Inline and remove the cs_fold_* functions.

    Because they now have a single call site each.
    
    Also rename `cs_fold1` as `cs_fold`, now that it's the only folding
    function left.
    nnethercote committed Jul 4, 2022
    Configuration menu
    Copy the full SHA
    0da063c View commit details
    Browse the repository at this point in the history