Skip to content

Rustfmt deletes comments in first position of trait bound #6051

Open
@sffc

Description

@sffc

Example code:

    pub fn try_new_with_date_length_unstable<P>(
        provider: &P,
        locale: &DataLocale,
        length: length::Date,
    ) -> Result<Self, Error>
    where
        P: // Explanatory comment about the bounds
            ?Sized
            + DataProvider<BuddhistDatePatternV1Marker>
            + DataProvider<BuddhistYearNamesV1Marker>
            + DataProvider<BuddhistMonthNamesV1Marker>
    { ... }

Running this through rustfmt deletes the // Explanatory comment about the bounds.

Workaround: move the ?Sized into the first position. If your bound is not ?Sized, you can use Sized. The comment is retained:

    pub fn try_new_with_date_length_unstable<P>(
        provider: &P,
        locale: &DataLocale,
        length: length::Date,
    ) -> Result<Self, Error>
    where
        P: ?Sized
            // Explanatory comment about the bounds
            + DataProvider<BuddhistDatePatternV1Marker>
            + DataProvider<BuddhistYearNamesV1Marker>
            + DataProvider<BuddhistMonthNamesV1Marker>
    { ... }

Possibly related to #3669, #4666, #5059 but the examples are in different contexts so I thought I would file a new issue with this test case.

CC @Manishearth

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-commentsbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions