Skip to content

rustfmt wraps comments too tightly on first trait bound #7148

Closed

Description

@jacobsa

Sometimes I have comments to put on bounds within a where clause. For example:

unsafe impl<T> Sync for PinnedOnceLock<T>
where
    // Shared access to the PinnedOnceLock<T> also allows for creating T on a thread that may be
    // different from the one that later destroys the PinnedOnceLock<T>. So T also needs to be Send.
    T: Send,
    // Shared access to the PinnedOnceLock<T> allows for shared access to T, so T needs to be Sync
    // in order for the PinnedOnceLock<T> to be Sync.
    T: Sync,
{
}

For some reason, in this syntactic position wrap_comments wants to make the first comment much shorter than the second, even though comment_width is set appropriately:

> cat config.toml
wrap_comments = true
comment_width = 100

> rustfmt +nightly --version
rustfmt 1.11.0-nightly (75a75c3e0a 2026-09-26)

> rustfmt +nightly --emit=stdout --config-path config.toml foo.rs
unsafe impl<T> Sync for PinnedOnceLock<T>
where
    // Shared access to the PinnedOnceLock<T> also allows for
    // creating T on a thread that may be different from
    // the one that later destroys the PinnedOnceLock<T>. So T
    // also needs to be Send.
    T: Send,
    // Shared access to the PinnedOnceLock<T> allows for shared access to T, so T needs to be Sync
    // in order for the PinnedOnceLock<T> to be Sync.
    T: Sync,
{
}

Activity

  1. added
    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICE
    on Sep 27, 2026
  2. added
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Sep 27, 2026
  3. maxdexh commented on Sep 28, 2026

    @maxdexh
  4. jieyouxu commented on Sep 28, 2026

    @jieyouxu
  5. transferred this issue fromrust-lang/ruston Sep 28, 2026
  6. added and removed
    needs-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.
    on Sep 28, 2026
  7. added 3 commits that reference this issue on Oct 2, 2026
    bf43b7b
    df2780a
    3297756
  8. jacobsa commented on Oct 2, 2026

    @jacobsa
    Author

    Thanks very much!

  9. added a commit that references this issue on Oct 5, 2026
    e8aa31c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-commentsArea: commentsA-trait-boundsArea: trait boundsC-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEUO-comment_widthUnstable option: comment_widthUO-wrap_commentsUnstable option: wrap_comments

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions