`use_try_shorthand = true` disallows formatting on chains with comments
Open
Nobody has claimed this yet.
A-call-chains
A-comments
C-bug
only-with-option
SO-use_try_shorthand
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
rustfmt.toml
# rustfmt.toml
# outdated default — `?` was unstable at the time
# additionally the `try!` macro is deprecated now
use_try_shorthand =true
main.rs
fn main() {
let e: Result<(), &str> = Ok(());
let _e = e // hello comment
.map_err(|_| "This is an error message") // Hello comment - Fails to format
.map(|_| ());
println!("Hello, world!");
}
rustfmt version:
`rustfmt 1.7.0-stable (07dca489 2024-02-04)`
Nightly:
`rustfmt 1.7.0-nightly (1388d7a0 2024-03-20)`
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
Reproduce the formatting failure using the shown rustfmt.toml and main.rs, with use_try_shorthand = true and comments in the method chain. Start by tracing rustfmt's handling of try shorthand and commented chains, then add regression coverage for this example. Done means the chain formats successfully without dropping or misplacing either comment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100