Skip to content

Tuples or methods with two unsafe blocks are ugly formatted #6756

@sorairolake

Description

@sorairolake

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions