Rustfmt changes meaning of closure, also not idempotent
Open
Nobody has claimed this yet.
A-closures
C-bug
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Input program, which compiles:
https://play.rust-lang.org/?edition=2018&gist=046bcee6f5a6524efd1cf0d71b383fef
fn main() {
|| {
println!();
|| 0
}().to_string();
}
As of rustfmt 2.0.0-rc.1-nightly (b9138e06 2020-02-10), rustfmt incorrectly changes this to the following which does not compile:
fn main() {
|| {
{
println!();
|| 0
}()
.to_string()
};
}
It is also not idempotent, since running rustfmt again changes it to:
fn main() {
|| {
{
println!();
|| 0
}
().to_string()
};
}
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 with the Rust playground reproducer linked in the issue and run rustfmt on the provided closure, then run it again on the output. Trace the formatter behavior that changes the closure's meaning and verify that the formatted program still compiles and remains unchanged on a second run.
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