Skip to content

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

Closed
@Havvy

Description

@Havvy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions