Skip to content

macro_rules broken on latest nightly #138178

Closed
@vdrn

Description

@vdrn

After updating to latest nightly, my code that uses macro_rules is broken.
Example: (playground)

macro_rules! create_enum {
    ($enum:ident, $ty:ty) => {
        #[repr($ty)]
        pub enum $enum {
            Variant,
            Variant2,
        }
    };
}
create_enum!(Enum, u32);

fn main() {
    assert_eq!(size_of::<Enum>(), 1, "this should fail but it passes");
    assert_eq!(size_of::<Enum>(), 4, "this should pass but it fails");
}

I would expect create_enum!(Enum,u32) to expand to:

#[repr(u32)]
pub enum Enum {
    Variant,Variant2
}

Instead, it seems that it expands to:

#[repr()]
pub enum Enum {
    Variant,Variant2
}

Rustc and Rust analyzer both catch this, and produces diagnostic:

unused_attribute attribute repr with an empty list has no effect

On the other hand, if I run Inline macro code action, it produces correct result.

As can be seen from assert_eqs in main(), size of Enum should be 4, but it is 1 instead.

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (b74da9613 2025-03-06)
binary: rustc
commit-hash: b74da9613a8cb5ba67a985f71325be0b7b16c0dd
commit-date: 2025-03-06
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.S-needs-infoStatus: The issue lacks details necessary to triage or act on it.T-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