rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
5.98k stars 878 forks source link

Freeze and severe memory leak trying to format very short file #6215

Closed shellixyz closed 3 months ago

shellixyz commented 3 months ago

rustfmt 1.7.0-stable (129f3b9 2024-06-10)

To reproduce try to format this text:

cfg_if!(
    if #[cfg(feature = "xxxx")] {
        if #[cfg(feature = "yyyy")] {
            pub const C1: u8 = 1;
        } else {
            pub const C2: u8 = 2;
        }
    }
);
ytmimi commented 3 months ago

Duplicate of https://github.com/rust-lang/rustfmt/issues/4442. I've added a test case for this in https://github.com/rust-lang/rustfmt/pull/5341