rustfmt
rustfmt copied to clipboard
Format crashes unexpectedly.
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
@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.
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.
That would be very helpful!
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.
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?
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],
},
}
All very useful details. Thank you for sharing 😁