Summary
Just recording something I ran into during my (ongoing) dive into chain formatting
I tried to format this code:
fn main() {
let _ = r#try!(root)/* this is a comment*/.bar;
}
Expected behavior
It would be formatted to something like
fn main() {
let _ = root? /* this is a comment*/
.bar;
}
Actual behavior
It was formatted to invalid code:
fn main() {
let _ = root? )/* this is a comment*/
.bar;
}
Configuration
Only needs the use_try_shorthand option
Reproduction Steps
rustfmt --config use_try_shorthand=true ./file.rs
Meta
Also reproduced on 1141ee711fc87bf51ff8934c09a9d608b34e50bf (a recent HEAD of master)
$ rustfmt --version
rustfmt 1.10.0-nightly (bff8e12ff5 2026-08-26)
Summary
Just recording something I ran into during my (ongoing) dive into chain formatting
I tried to format this code:
Expected behavior
It would be formatted to something like
Actual behavior
It was formatted to invalid code:
Configuration
Only needs the
use_try_shorthandoptionReproduction Steps
Meta
Also reproduced on
1141ee711fc87bf51ff8934c09a9d608b34e50bf(a recentHEADofmaster)