rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

rusfmt hangs when using cfg-if macro

Open gliderkite opened this issue 5 years ago • 3 comments

rusfmt hangs when using cfg-if macro

To reproduce run rustftm main.rs, where:

// main.rs
cfg_if::cfg_if! {
    if #[cfg(not(feature = "client"))] {
        if #[cfg(feature = "server")] {
        }
    }
}
rustfmt -V
rustfmt 1.4.18-stable (8157a3f 2020-07-15)

From the logs RUST_LOG=trace rustftm main.rs I can see it just keeps logging:

[2020-09-29T14:17:39Z DEBUG rustc_ap_rustc_parse::parser::attr] parse_outer_attributes: self.token=Token { kind: Ident("if", false), span: Span { lo: BytePos(67), hi: BytePos(69), ctxt: #0 } }
[2020-09-29T14:17:39Z DEBUG rustc_ap_rustc_parse::parser::attr] parse_outer_attributes: self.token=Token { kind: Ident("if", false), span: Span { lo: BytePos(67), hi: BytePos(69), ctxt: #0 } }
[2020-09-29T14:17:39Z DEBUG rustc_ap_rustc_parse::parser::attr] parse_outer_attributes: self.token=Token { kind: Ident("if", false), span: Span { lo: BytePos(67), hi: BytePos(69), ctxt: #0 } }

gliderkite avatar Sep 29 '20 14:09 gliderkite

This is most minimal reproduction I've found:

cfg_if! {
    if #[_] { if }
}

Although I should note that it doesn't produce any debug messages when run with RUST_LOG=trace like yours does.

mpfaff avatar Jun 28 '22 18:06 mpfaff

current minimal reproduction

cfg_if! {
    if #[cfg()] { if }
}

youknowone avatar Jul 25 '24 14:07 youknowone

#6251 could fix this bug 6 months ago, but closed in favor of #5341. #5341 doesn't look go well for months though.

@ytmimi for what? why don't you merge a simple fix and add a revert commit of that in front of your patch?

youknowone avatar Feb 12 '25 06:02 youknowone