Skip to content

Putting #[derive] before a macro attribute results in a bad error #89227

Description

@meithecatte

I don't know, off the top of my head, what attribute macros are available on the playground, so I'll use the crate I'm maintaining. The details of it are pretty much irrelevant anyway.

Given the following code:

#[derive(Copy, Clone)]
#[enumflags2::bitflags]
#[repr(u8)]
enum Foo {
    A = 1,
}

fn main() {}

The current output is:

error[E0658]: macro attributes in `#[derive]` output are unstable
 --> src/main.rs:2:3
  |
2 | #[enumflags2::bitflags]
  |   ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #81119 <https://github.com/rust-lang/rust/issues/81119> for more information
  = help: add `#![feature(macro_attributes_in_derive_output)]` to the crate attributes to enable

A few versions back (I've tested 1.41.1), we were outputting the following, much more legible error:

error: macro attributes must be placed before `#[derive]`
 --> src/main.rs:2:1
  |
2 | #[enumflags2::bitflags]
  | ^^^^^^^^^^^^^^^^^^^^^^^

This is motivated by meithecatte/enumflags2#37 — it took me a moment to understand what was happening when a user reported that error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions