Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macro_rules broken on latest nightly #138178

Closed
vdrn opened this issue Mar 7, 2025 · 3 comments
Closed

macro_rules broken on latest nightly #138178

vdrn opened this issue Mar 7, 2025 · 3 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. S-needs-info Status: The issue lacks details necessary to triage or act on it. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@vdrn
Copy link

vdrn commented Mar 7, 2025

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

@vdrn vdrn added the C-bug Category: This is a bug. label Mar 7, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 7, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Mar 7, 2025

This sounds like a duplicate of #137662, which should be fixed in tomorrows nightly by #137758.

@Noratrieb Noratrieb added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-needs-info Status: The issue lacks details necessary to triage or act on it. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 7, 2025
@Noratrieb
Copy link
Member

yeah, please try again tomorrow and if it passes you can close the issue

@vdrn
Copy link
Author

vdrn commented Mar 8, 2025

Confirmed, issue is fixed now.

@vdrn vdrn closed this as completed Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. S-needs-info Status: The issue lacks details necessary to triage or act on it. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants