rustfmt
rustfmt copied to clipboard
Odd formatting of empty `where` clause
The following is rustfmt's formatting on 2025-02-17 4d91de4e48 (the version currently on the Rust Playground):
impl<'a, T, I> Ptr<'a, T, I>
where
T: 'a + TransparentWrapper<I, UnsafeCellVariance = Covariant> + ?Sized,
I: Invariants,
{
pub(crate) fn transparent_wrapper_into_inner(
self,
) -> Ptr<
'a,
T::Inner,
(
I::Aliasing,
<T::AlignmentVariance as AlignmentVariance<I::Alignment>>::Applied,
<T::ValidityVariance as ValidityVariance<I::Validity>>::Applied,
),
>
where {
}
}
The where clause should probably be indented by four spaces.
Also note that, when wrapped in a module, the where clause is still not indented at all:
mod foo {
impl<'a, T, I> Ptr<'a, T, I>
where
T: 'a + TransparentWrapper<I, UnsafeCellVariance = Covariant> + ?Sized,
I: Invariants,
{
pub(crate) fn transparent_wrapper_into_inner(
self,
) -> Ptr<
'a,
T::Inner,
(
I::Aliasing,
<T::AlignmentVariance as AlignmentVariance<I::Alignment>>::Applied,
<T::ValidityVariance as ValidityVariance<I::Validity>>::Applied,
),
>
where {
}
}
}
Smaller example:
struct MyStruct;
impl MyStruct {
pub const unsafe fn wow_this_is_so_long_i_might_have_to_do_some_line_wrapping(x: u8) -> u8
where {
x
}
}
Rustfmt currently accepts this. It appears that it simply doesn't move the where clause at all if it's empty, since this also is unchanged by rustfmt:
struct MyStruct;
impl MyStruct {
pub const unsafe fn wow_this_is_so_long_i_might_have_to_do_some_line_wrapping(x: u8) -> u8 where
{
x
}
}
Think this might be a duplicate of https://github.com/rust-lang/rustfmt/issues/5407