Skip to content

derive may only be applied to structs, enums and unions error should only show once per derive #43927

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

Closed
Havvy opened this issue Aug 17, 2017 · 0 comments · Fixed by #44055
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Havvy
Copy link
Contributor

Havvy commented Aug 17, 2017

The error `derive` may only be applied to structs, enums and unions currently fires for each derived trait in the attribute pointing at the trait it is implementing. It should instead fire once per attribute, pointing at the derive.

Minimal Code

#![allow(dead_code)]

#![derive(Debug, PartialEq, Eq)]
struct DerivedOn;

fn main() {}

Output

   Compiling playground v0.0.1 (file:///playground)
error: `derive` may only be applied to structs, enums and unions
 --> src/main.rs:3:29
  |
3 | #![derive(Debug, PartialEq, Eq)]
  |                             ^^

error: `derive` may only be applied to structs, enums and unions
 --> src/main.rs:3:18
  |
3 | #![derive(Debug, PartialEq, Eq)]
  |                  ^^^^^^^^^

error: `derive` may only be applied to structs, enums and unions
 --> src/main.rs:3:11
  |
3 | #![derive(Debug, PartialEq, Eq)]
  |           ^^^^^

error: aborting due to 3 previous errors

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Expected Output

   Compiling playground v0.0.1 (file:///playground)
error: `derive` may only be applied to structs, enums and unions
 --> src/main.rs:3:29
  |
3 | #![derive(Debug, PartialEq, Eq)]
  |    ^^^^^^

error: aborting due to 1 previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@sfackler sfackler added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 18, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Aug 20, 2017
zackmdavis added a commit to zackmdavis/rust that referenced this issue Sep 22, 2017
A slight eccentricity of this change is that now non-ADT-derive errors prevent
derive-macro-not-found errors from surfacing (see changes to the
gating-of-derive compile-fail tests).

Resolves rust-lang#43927.
bors added a commit that referenced this issue Sep 23, 2017
…seyfried

only set non-ADT derive error once per attribute, not per trait

I found the expansion code very hard to follow, leaving me unsure as to whether this might somehow be done better, but this patch does give us the behavior requested in #43927 (up to exact choice of span; here, it's the entire attribute, not just the `derive` token).

(Note to GitHub robots: _resolves #43927_.)

r? @jseyfried
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants