`cargo-fmt` failed with infinite memory request?

Using cfg-if crate with version 1.0.0, cargo fmt failed with error message: "memory allocation of 25769803776 bytes failed". The scary constant changes sometimes, but it's still a GB order.

minimized to reproduce:

cfg_if::cfg_if! {
    if #[cfg(windows)] {

It's so strange that everything is OK if I replace "compile_error!{..}" with "compile_error!(..)".

I'm not sure whether cargo-fmt or cfg-if goes wrong. In any case cargo-fmt gets polluted, and I think there's a bug.


I can reproduce this with just rustfmt using both stable and nightly. It seems to hang inside a special case for cfg_if formatting:

#0  0x00005555555dc7e7 in <rustc_parse::parser::Parser>::parse_item_common ()
#1  0x00005555555dc281 in <rustc_parse::parser::Parser>::parse_item ()
#2  0x00005555557a0964 in rustfmt_nightly::parse::macros::cfg_if::parse_cfg_if_inner ()
#3  0x00005555557a0501 in <rustfmt_nightly::modules::visitor::CfgIfVisitor as rustc_ast::visit::Visitor>::visit_mac_call ()
#4  0x000055555575c01e in rustc_ast::visit::walk_item::<rustfmt_nightly::modules::visitor::CfgIfVisitor> ()
#5  0x000055555571fb26 in <rustfmt_nightly::modules::ModResolver>::visit_cfg_if ()
#6  0x000055555571ff21 in <rustfmt_nightly::modules::ModResolver>::visit_mod_from_ast ()

Please report an issue at Issues · rust-lang/rustfmt · GitHub.