Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

does not finish when trying to format a program with a ridiculous number of nested match #6079

Open
cscherrNT opened this issue Feb 16, 2024 · 0 comments
Labels
a-matches match arms, patterns, blocks, etc p-low

Comments

@cscherrNT
Copy link

cscherrNT commented Feb 16, 2024

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 */
@ytmimi ytmimi added p-low a-matches match arms, patterns, blocks, etc labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-matches match arms, patterns, blocks, etc p-low
Projects
None yet
Development

No branches or pull requests

2 participants