-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.S-needs-infoStatus: The issue lacks details necessary to triage or act on it.Status: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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
reprwith 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
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.Category: This is a bug.S-needs-infoStatus: The issue lacks details necessary to triage or act on it.Status: 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.Relevant to the compiler team, which will review and decide on the PR/issue.