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

ICE formatting macro #5928

Closed
SamRodri opened this issue Sep 28, 2023 · 5 comments
Closed

ICE formatting macro #5928

SamRodri opened this issue Sep 28, 2023 · 5 comments
Labels

Comments

@SamRodri
Copy link

SamRodri commented Sep 28, 2023

Formatting this reduced code:

macro_rules! foo {
    ($self:ident) => {
        foo!($self.Bar::X)
    };
}

Causes an unknown panic in stable and nightly:

note: rustc 1.72.1 (d5c2e9c34 2023-09-13) running on x86_64-pc-windows-msvc

query stack during panic:
end of query stack
note: rustc 1.74.0-nightly (5ae769f06 2023-09-26) running on x86_64-pc-windows-msvc

query stack during panic:
end of query stack

The nightly ICE file can't be written in Windows (os error 123, rust-lang/rust#115180), in Linux it is is empty.

@ytmimi
Copy link
Contributor

ytmimi commented Sep 28, 2023

Thanks for the report. Out of curiosity, does that macro compile? I think the issue is with $self.Bar::X. If we change it to $self::Bar::X then we format without the ICE.

macro_rules! foo {
    ($self:ident) => {
        foo!($self::Bar::X)
    };
}

@SamRodri
Copy link
Author

The original macro compiles, I reduced to this one.

Here is a reduced that compiles and causes the ICE:

macro_rules! foo {
    ($self:ident) => {
        foo!($self.Bar::X)
    };
    ($self:ident.$State:ident::$Discriminant:ident) => {

    };
}

pub struct Foo {}
impl Foo {
    pub fn set_state(&mut self) {
        foo!(self);
    }
}

I worked around the issue on my end by replacing the separators with comma $self,Bar,X so the issue is probably in that line like you said.

@ytmimi
Copy link
Contributor

ytmimi commented Sep 28, 2023

Thanks for putting together the minimal reproduction that compiles. That should help when diving into what's going on here.

@calebcartwright
Copy link
Member

The ICE details getting swallowed is caused by rust-lang/rust#111529

@SamRodri
Copy link
Author

SamRodri commented Jan 6, 2025

Tested this again with rustfmt 1.8.0-stable (90b35a6239 2024-11-26), the issue is fixed. Not sure when it was fixed.

@SamRodri SamRodri closed this as completed Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants