Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,10 @@ fn rewrite_ty<R: Rewrite>(
result.push_str(&generics_str);
}

// The bounds are written out here, so anything the `where` clause treats as a
// missing comment has to start after them, not after the generics.
let mut span_end_before_where = generics.span.hi();

if let Some(bounds) = generic_bounds_opt {
if !bounds.is_empty() {
// 2 = `: `
Expand All @@ -1771,6 +1775,7 @@ fn rewrite_ty<R: Rewrite>(
.rewrite_result(context, shape)
.map(|s| format!(": {}", s))?;
result.push_str(&type_bounds);
span_end_before_where = bounds.last().unwrap().span().hi();
}
}

Expand All @@ -1787,7 +1792,7 @@ fn rewrite_ty<R: Rewrite>(
false,
"=",
None,
generics.span.hi(),
span_end_before_where,
option,
)?;
result.push_str(&before_where_clause_str);
Expand Down
9 changes: 9 additions & 0 deletions tests/source/issue-6234.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait Foo {
type Bar<'a>: Baz1 // comment
where Self: 'a;
}

trait Qux {
type Bar: Baz1 + Baz2 // comment
where Self: Sized;
}
13 changes: 13 additions & 0 deletions tests/target/issue-6234.rs

@ytmimi ytmimi Aug 22, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you help me understand why the comment was moved to the next line? I think I would have expected it to stay on the line where it was originally written.

@rustbot author

View changes since the review

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
trait Foo {
type Bar<'a>: Baz1
// comment
where
Self: 'a;
}

trait Qux {
type Bar: Baz1 + Baz2
// comment
where
Self: Sized;
}