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
After updating to latest nightly, my code that uses
macro_rulesis broken.Example: (playground)
I would expect
create_enum!(Enum,u32)to expand to:Instead, it seems that it expands to:
Rustc and Rust analyzer both catch this, and produces diagnostic:
On the other hand, if I run
Inline macrocode action, it produces correct result.As can be seen from
assert_eqs inmain(), size ofEnumshould be4, but it is1instead.Meta
rustc --version --verbose: