does not finish when trying to format a program with a ridiculous number of nested `match`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
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 */
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running rustfmt on the linked members/matchmatchmatch/src/main.rs reproduction and confirm the non-terminating behavior. Trace the formatter entry point handling the deeply nested match expressions, then define a bounded completion or error outcome and add a regression test for the reproduced nesting depth.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100