Skip to content

Rustfmt generates invalid code for associated type bounds with where-clause and comments #6761

@taiheioki

Description

@taiheioki

Input (Playground):

pub trait Trait {
    type I: Iterator<
        // This is an item
        Item = Self,
    >
    where
        Self: Copy;
}

Expected: rustfmt produces the same code as input.

Output: rustfmt produces the following invalid code

pub trait Trait {
    type I: Iterator<
        // This is an item
        Item = Self,
    >
    : Iterator<
    // This is an item
    Item = Self,
    >
    where
        Self: Copy;
}

Version

$ rustfmt --version
rustfmt 1.8.0-stable (ded5c06cf2 2025-12-08)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions