Description
When trying to format a program with a ridiculously nested datatype that is to be matched, rustfmt does not finish. It keeps a cpu core at 100%, but will not finish formatting even after 15 minutes. This might potentially break applications of rustfmt
in CI/CD scripts and waste ressources.
Expected behavior
rustfmt
finishes formatting quickly or returns some kind of error, explaining that it gives up on formatting ridiculously nested types/match statements.
Current behavior
rustfmt
just keeps going, presumably trying to format the document, using up a full cpu core. This seems to start at a depth of about 16 match
statements.
Reproduction
I know this source file is completely ridiculous, but bear with me. Note that compiling and running is near instantaneous.
See here for the full source and here for an example on how cpu time is wasted in context of CI/CD.
fn main() {
let deep_type = Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(Option::Some(Option::Some(
Option::Some(Option::Some(Option::Some(1337))),
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
;
match match match match match match match match match match match match match match match match match match
match match match match match match match match match match match match match match match match match match
match match match match match match match match match match match match match match match match match match
match match match match match match match match match match match match match match match match match match
match match match match match match match match match match match match match match match match
deep_type {
Some(inner) => inner,
None => unreachable!(),
} {
Some(inner) => inner,
None => unreachable!(),
} {
Some(inner) => inner,
None => unreachable!(),
} {
Some(inner) => inner,
None => unreachable!(),
} {
Some(inner) => inner,
None => unreachable!(),
/* it goes on a lot longer */