Tuples or methods with two `unsafe` blocks are ugly formatted
Open
Nobody has claimed this yet.
C-discussion
S-waiting-on-t-style
T-style
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
Tuples or methods with two unsafe blocks are formatted as follows:
let (n, m) = (unsafe { NonZeroU16::new_unchecked(u16::MAX) }, unsafe {
NonZeroU16::new_unchecked(u16::MAX)
});
let r = NonZeroU16::div_ceil(unsafe { NonZeroU16::new_unchecked(u16::MAX) }, unsafe {
NonZeroU16::new_unchecked(u16::MAX)
});
I think this is ugly.
Similar code without unsafe blocks would be formatted as follows:
let (n, m) = (
NonZeroU16::new(u16::MAX).unwrap(),
NonZeroU16::new(u16::MAX).unwrap(),
);
let r = NonZeroU16::div_ceil(
NonZeroU16::new(u16::MAX).unwrap(),
NonZeroU16::new(u16::MAX).unwrap(),
);
Similar to this, I think the first example should be formatted like this:
let (n, m) = (
unsafe { NonZeroU16::new_unchecked(u16::MAX) },
unsafe { NonZeroU16::new_unchecked(u16::MAX) },
);
let r = NonZeroU16::div_ceil(
unsafe { NonZeroU16::new_unchecked(u16::MAX) },
unsafe { NonZeroU16::new_unchecked(u16::MAX) },
);
$ rustfmt --version
rustfmt 1.8.0-nightly (fabece9e94 2025-12-25)
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 by reproducing the two examples with rustfmt and compare the current output with the desired formatting shown in the issue. Trace the formatter behavior for multiple unsafe blocks in tuple and method-call arguments, then add coverage and confirm both examples format as requested.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100