Skip to content

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

@meithecatte

Description

@meithecatte
Contributor

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.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Sep 24, 2021
petrochenkov

petrochenkov commented on Sep 24, 2021

@petrochenkov
Contributor

This is going to be stabilized by #87220 very soon.

meithecatte

meithecatte commented on Sep 24, 2021

@meithecatte
ContributorAuthor

Ah, so in that case the code will just start working? Great! I don't think any action is necessary here, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @petrochenkov@meithecatte

        Issue actions

          Putting #[derive] before a macro attribute results in a bad error · Issue #89227 · rust-lang/rust