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

Format crashes unexpectedly. #6052

Open
Frostie314159 opened this issue Feb 1, 2024 · 7 comments · May be fixed by #6087
Open

Format crashes unexpectedly. #6052

Frostie314159 opened this issue Feb 1, 2024 · 7 comments · May be fixed by #6087
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@Frostie314159
Copy link

I'm not sure what exactly caused this, since my crate uses generics extensively, but it seems to be related.
rustc-ice-2024-02-01T09_12_26-75080.txt

@ytmimi
Copy link
Contributor

ytmimi commented Feb 6, 2024

@Frostie314159 I appreciate you opening an issue. However, without a code snippet that can be used to reproduce the issue there's not much anyone can do to help. When you have a moment can you please provide a reproducible example, let us know what version of rustfmt you're using, and what configuration options you were using at the time of the crash.

@ytmimi ytmimi added the needs-mcve needs a Minimal Complete and Verifiable Example label Feb 6, 2024
@Frostie314159
Copy link
Author

Ok, in the meantime I've traced the issue down, it seemed to be related to enums having generic parameters with defaults and trait bounds, but without a where clause. Introducing the where clause fixed the issue. I'm currently on the go, but as soon as I get home, I will make an example.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 6, 2024

That would be very helpful!

@Frostie314159
Copy link
Author

After trying over and over to isolate the issue to a generic example, I was ultimately unable to do so. However I published a branch of my code with crash in it if that helps. Here is a link to the enum causing the crash: ieee80211-rs. I hope this helps to trace down the issue.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 7, 2024

No worries. I appreciate that you spent some time trying to narrow it down. Having a link to a repo where I can reproduce the issue is the next best thing to a minimal code snippet.

It would still be helpful to know what version of rustfmt you're using and if you were using any configuration options when you ran into this issue? Also, do you actually see a panic! or are files that you'd expect to be formatted just not getting formatted?

@Frostie314159
Copy link
Author

Frostie314159 commented Feb 8, 2024

I ran rustfmt -V, with this output:

rustfmt 1.7.0-nightly (5518eaa 2024-01-29)

I'm on the current nightly channel and am using the default config. When running rustfmt I get a panic and the file attached to the original comment gets emitted.
This is the original code, that caused the panic:

pub enum ManagementFrameBody<
    'a,
    RateIterator = SupportedRatesTLVReadRateIterator<'a>,
    ExtendedRateIterator = ExtendedSupportedRatesTLVReadRateIterator<'a>,
    TLVIterator: IntoIterator<Item = IEEE80211TLV<'a, RateIterator, ExtendedRateIterator>> = TLVReadIterator<'a>,
    ActionFramePayload = &'a [u8],
>
{
    Action(ActionFrameBody<ActionFramePayload>),
    ActionNoAck(ActionFrameBody<ActionFramePayload>),
    Beacon(BeaconFrameBody<'a, RateIterator, ExtendedRateIterator, TLVIterator>),
    ATIM,
    Unknown {
        sub_type: ManagementFrameSubtype,
        body: &'a [u8],
    },
}

Restructuring it to a where clause like this fixes the problem:

pub enum ManagementFrameBody<
    'a,
    RateIterator = SupportedRatesTLVReadRateIterator<'a>,
    ExtendedRateIterator = ExtendedSupportedRatesTLVReadRateIterator<'a>,
    TLVIterator = TLVReadIterator<'a>,
    ActionFramePayload = &'a [u8],
> where
    TLVIterator: IntoIterator<Item = IEEE80211TLV<'a, RateIterator, ExtendedRateIterator>>,
{
    Action(ActionFrameBody<ActionFramePayload>),
    ActionNoAck(ActionFrameBody<ActionFramePayload>),
    Beacon(BeaconFrameBody<'a, RateIterator, ExtendedRateIterator, TLVIterator>),
    ATIM,
    Unknown {
        sub_type: ManagementFrameSubtype,
        body: &'a [u8],
    },
}

@ytmimi
Copy link
Contributor

ytmimi commented Feb 8, 2024

All very useful details. Thank you for sharing 😁

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. and removed needs-mcve needs a Minimal Complete and Verifiable Example labels Feb 8, 2024
@MarcusGrass MarcusGrass linked a pull request Feb 22, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants