Long trait bounds don't get broken up in rustdoc

848a95d
Opened by Clar Fon at 2022-02-07 19:54:44

See also: rust-lang-nursery/fmt-rfcs#75

Here's an example of a similarly awful-looking set of bounds: (link)

Copy-pasted here:

pub trait IndexRanges<Idx>: Index<Range<Idx>, Output = Self::Output> + Index<RangeTo<Idx>, Output = Self::Output> + Index<RangeFrom<Idx>, Output = Self::Output> + Index<RangeInclusive<Idx>, Output = Self::Output> + Index<RangeToInclusive<Idx>, Output = Self::Output> + Index<RangeFull> { }

I've also broken up the impl using a where condition, which does format nicely:

impl<T: ?Sized, Idx> IndexRanges<Idx> for T
where
    T: Index<Range<Idx>, Output = T::Output>,
    T: Index<RangeTo<Idx>, Output = T::Output>,
    T: Index<RangeFrom<Idx>, Output = T::Output>,
    T: Index<RangeInclusive<Idx>, Output = T::Output>,
    T: Index<RangeToInclusive<Idx>, Output = T::Output>,
    T: Index<RangeFull>, 

But it'd be nice if there were some way to make the rustdoc for these a bit less… awful, by default. Preferably without having to require that the user format their code accordingly.

  1. Here's an example of some long bounds: num_traits::NumAssignOps

    Copy-pasted here:

    pub trait NumAssignOps<Rhs = Self>: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs> + RemAssign<Rhs> { }
    

    Rustfmt, when given an adequately small width limit, will turn this into:

    pub trait NumAssignOps<Rhs = Self>:
        AddAssign<Rhs>
        + SubAssign<Rhs>
        + MulAssign<Rhs>
        + DivAssign<Rhs>
        + RemAssign<Rhs>
    {
    }
    

    It'd be nice if there were some way to make the rustdoc for these a bit less… awful, by default. Preferably without having to require that the user format their code accordingly.

    Clar Fon at 2022-02-07 19:53:47

  2. Going through old issues, updated this to include a more recent example + how rustfmt handles this, since rustfmt didn't handle it back when this issue was made.

    Clar Fon at 2022-02-07 19:54:44