rust-lang / rust-lang/rustfmt

Odd formatting of empty `where` clause

Open
#6,488 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

I-poor-formatting S-duplicate
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

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 {
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the supplied Rust examples with the rustfmt version described in the issue, including the nested module case. Trace the formatting path for an empty where clause and add a regression test covering both examples. Done means the where clause is indented consistently with the surrounding impl, including inside a module.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.