rust-lang / rust-lang/rustfmt

rustfmt hangs indefinitely parsing large decimal literals and deep parentheses

Open
#6,357 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the hang with the Rust snippet from the issue by running cargo fmt or rustfmt --edition 2021 on the shown lib.rs. Trace the formatter entry point and parsing of the large decimal literals and nested parentheses; done means this input formats or fails promptly rather than hanging indefinitely.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.