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

rustfmt hangs indefinitely parsing large decimal literals and deep parentheses #6357

Open
chancehudson opened this issue Oct 4, 2024 · 3 comments
Labels
bug Panic, non-idempotency, invalid code, etc.

Comments

@chancehudson
Copy link

Rustfmt hangs indefinitely formatting the following code:

#![allow(unused)]
fn main() {
    let x = 0.5;
    let z = 1.0 + x * (0.69314718055994595236057875808910466730594635009766 + x * (0.24022650695906239137755733281665015965700149536133 + x * (5.5504108665615274620375174663422512821853160858154e-2 + x * (9.618129099454324551499162510026508243754506111145e-3 + x * (1.33335586337906793555352358282561908708885312080383e-3 + x * (1.54035121930721417794415972757349209132371470332146e-4 + x * (1.52531771389177337269358811222552674280450446531177e-5 + x * (1.32083432055888705908372905001302299865528766531497e-6 + x * (1.02533862337995870705910481015393775905408801918384e-7 + x * (6.5588174947098374579243424450491345423230882261123e-9 + x * 6.264729520369589538179779228995857492945376066018e-10))))))))));
}

possibly related #5626

output from cargo fmt after a few minutes:

> cargo fmt --verbose
[lib (2021)] "/Users/chance/work/discrete-gaussian/src/lib.rs"
rustfmt --edition 2021 /Users/chance/work/discrete-gaussian/src/lib.rs
^C
@ytmimi
Copy link
Contributor

ytmimi commented Oct 4, 2024

Thanks for the report. What version of rustfmt are you using? Can you run rustfmt --version?

@ytmimi ytmimi added the bug Panic, non-idempotency, invalid code, etc. label Oct 4, 2024
@chancehudson
Copy link
Author

chancehudson commented Oct 4, 2024

> rustfmt --version
rustfmt 1.7.1-stable (eeb90cda 2024-09-04)

@therealhappy
Copy link

Hi,

I attempted to reproduce the problem you're encountering. As part of my testing, I created a rustfmt.toml file and set max_width = 600.

With the provided test data, the task ran for approximately 40 seconds and completed successfully without any errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc.
Projects
None yet
Development

No branches or pull requests

3 participants