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

Improve error messages involving derive and packed. #99581

Closed

Commits on Jul 25, 2022

  1. Improve error messages involving derive and packed.

    There are two errors involving `derive` and `packed`.
    
    ```
    `#[derive]` can't be derived on a `#[repr(packed)]` struct with type or const parameters
    `#[derive]` can't be derived on a `#[repr(packed)]` struct that does not derive Copy
    ```
    The second one overstates things. It is possible to use derive on a
    repr(packed) struct that doesn't derive Copy in two cases.
    - If all the fields within the struct meet the required alignment: 1 for
      `repr(packed)`, or `N` for `repr(packed(N))`.
    - If `Default` is the only trait derived.
    
    This commit improves things in a few ways.
    - Changes the errors to say `$TRAIT can't be derived on this ...`.
      This is more accurate, because it's just $TRAIT and *this* packed
      struct that are a problem, not *all* derived traits on *all* packed
      structs.
    - Removed the E0133 error code, because it's incorrect, being a code
      relating to `unsafe`.
    - Adds more details to the "ERROR" lines in the test case, enough to
      distinguish between the two error messages.
    - Adds more cases to the test case that don't cause errors, e.g. `Default`
      derives.
    - Uses a wider variety of builtin traits in the test case, for better coverage.
    nnethercote committed Jul 25, 2022
    Configuration menu
    Copy the full SHA
    f6305dd View commit details
    Browse the repository at this point in the history