From 7d688f0b91b6a5608b329fd539c636019fb2088b Mon Sep 17 00:00:00 2001 From: saberoueslati Date: Thu, 6 Aug 2026 09:02:58 +0100 Subject: [PATCH 1/3] fix: preserve comments around associated type bounds --- src/items.rs | 48 ++++++++++++++++-- tests/source/issue-6761.rs | 94 ++++++++++++++++++++++++++++++++++++ tests/target/issue-6761.rs | 99 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 236 insertions(+), 5 deletions(-) create mode 100644 tests/source/issue-6761.rs create mode 100644 tests/target/issue-6761.rs diff --git a/src/items.rs b/src/items.rs index a63fd874487..1f4f97cd733 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1762,15 +1762,53 @@ fn rewrite_ty( result.push_str(&generics_str); } + // Default keeps today's behavior when there are no bounds, so comments between + // the ident and `where` are still recovered. + let mut span_end_before_where = generics.span.hi(); + if let Some(bounds) = generic_bounds_opt { if !bounds.is_empty() { // 2 = `: ` let shape = Shape::indented(indent, context.config); let shape = shape.offset_left(result.len() + 2, span)?; - let type_bounds = bounds - .rewrite_result(context, shape) - .map(|s| format!(": {}", s))?; - result.push_str(&type_bounds); + let type_bounds = bounds.rewrite_result(context, shape)?; + + // The bounds rewrite only covers the bounds themselves, so comments + // around the `:` would otherwise be dropped. Recover them on either + // side of the colon, keeping the exact `: ` layout when there are none. + let bounds_lo = bounds[0].span().lo(); + let colon_pos = context + .snippet_provider + .span_after(mk_sp(generics.span.hi(), bounds_lo), ":"); + let before_colon = mk_sp(generics.span.hi(), colon_pos - BytePos(1)); + let after_colon = mk_sp(colon_pos, bounds_lo); + + if contains_comment(context.snippet(before_colon)) { + result = combine_strs_with_missing_comments( + context, + &result, + ":", + before_colon, + shape, + true, + )?; + } else { + result.push(':'); + } + + if contains_comment(context.snippet(after_colon)) { + result = combine_strs_with_missing_comments( + context, + &result, + &type_bounds, + after_colon, + shape, + true, + )?; + } else { + result.push_str(&format!(" {}", type_bounds)); + } + span_end_before_where = bounds[bounds.len() - 1].span().hi(); } } @@ -1787,7 +1825,7 @@ fn rewrite_ty( false, "=", None, - generics.span.hi(), + span_end_before_where, option, )?; result.push_str(&before_where_clause_str); diff --git a/tests/source/issue-6761.rs b/tests/source/issue-6761.rs new file mode 100644 index 00000000000..26734f707fc --- /dev/null +++ b/tests/source/issue-6761.rs @@ -0,0 +1,94 @@ +#![feature(associated_type_defaults)] + +// Case 1: exact issue repro (comment inside bounds + before-where clause). +pub trait Trait { + type I: Iterator< + // This is an item + Item = Self, + > + where + Self: Copy; +} + +// Case 2: comment between the bound and `where`. +trait Bar1 { + type B: Iterator // trailing + where + Self: Copy; +} + +// Case 3: a `/` appears in the bounds without being a comment. +trait Foo {} +trait Baz { + type C: Foo<{ 6 / 2 }> + where + Self: Copy; +} + +// Case 4: bound + RHS + trailing where clause (associated type default). +trait Bound {} +impl Bound for () {} +trait Qux { + type D: Bound = () where Self: Copy; +} + +// Case 5a: associated type in an impl block, no bounds (bounds have no +// effect on impl assoc types and are rejected by rustc), still exercises +// the shared rewrite_ty/where-clause path. +trait Gat { + type I + where + T: Copy; +} +struct S; +impl Gat for S { + type I + // comment before where + where + T: Copy, + = Vec; +} + +// Case 5b: free type alias, no bounds (bounds have no effect outside trait +// definitions), still exercises the shared rewrite_ty/where-clause path. +type E +// a free comment +where + T: Copy, += Vec; + +// Case 6: no bounds + comment before `where` (guards the preserved +// generics.span.hi() default). +trait NoBounds { + type F // just a comment + where + Self: Copy; +} + +// Case 7: comments around the `:` must not be dropped. The bounds rewrite +// covers only the bounds themselves, so these are recovered separately. +trait AroundColon { + type G: /* after colon */ Bound + where + Self: Copy; + + type H: /* c1 */ Bound + Bound + where + Self: Copy; + + type I: // line comment after colon + Bound + where + Self: Copy; + + type J /* before colon */: Bound + where + Self: Copy; +} + +// Case 8: comment around the `:` on a generic associated type. +trait AroundColonGat { + type K: /* generics too */ Bound + where + U: Copy; +} diff --git a/tests/target/issue-6761.rs b/tests/target/issue-6761.rs new file mode 100644 index 00000000000..9e2d412a4a4 --- /dev/null +++ b/tests/target/issue-6761.rs @@ -0,0 +1,99 @@ +#![feature(associated_type_defaults)] + +// Case 1: exact issue repro (comment inside bounds + before-where clause). +pub trait Trait { + type I: Iterator< + // This is an item + Item = Self, + > + where + Self: Copy; +} + +// Case 2: comment between the bound and `where`. +trait Bar1 { + type B: Iterator + // trailing + where + Self: Copy; +} + +// Case 3: a `/` appears in the bounds without being a comment. +trait Foo {} +trait Baz { + type C: Foo<{ 6 / 2 }> + where + Self: Copy; +} + +// Case 4: bound + RHS + trailing where clause (associated type default). +trait Bound {} +impl Bound for () {} +trait Qux { + type D: Bound + = () + where + Self: Copy; +} + +// Case 5a: associated type in an impl block, no bounds (bounds have no +// effect on impl assoc types and are rejected by rustc), still exercises +// the shared rewrite_ty/where-clause path. +trait Gat { + type I + where + T: Copy; +} +struct S; +impl Gat for S { + type I + // comment before where + where + T: Copy, + = Vec; +} + +// Case 5b: free type alias, no bounds (bounds have no effect outside trait +// definitions), still exercises the shared rewrite_ty/where-clause path. +type E +// a free comment +where + T: Copy, += Vec; + +// Case 6: no bounds + comment before `where` (guards the preserved +// generics.span.hi() default). +trait NoBounds { + type F + // just a comment + where + Self: Copy; +} + +// Case 7: comments around the `:` must not be dropped. The bounds rewrite +// covers only the bounds themselves, so these are recovered separately. +trait AroundColon { + type G: /* after colon */ Bound + where + Self: Copy; + + type H: /* c1 */ Bound + Bound + where + Self: Copy; + + type I: // line comment after colon + Bound + where + Self: Copy; + + type J /* before colon */ : Bound + where + Self: Copy; +} + +// Case 8: comment around the `:` on a generic associated type. +trait AroundColonGat { + type K: /* generics too */ Bound + where + U: Copy; +} From a2ec7373f776231fc47a479a55a7a2b39a5c3a36 Mon Sep 17 00:00:00 2001 From: saberoueslati Date: Sat, 22 Aug 2026 23:23:31 +0100 Subject: [PATCH 2/3] addressed review comments --- src/items.rs | 16 +- .../associated-type-bounds-with-comments.rs | 279 +++++++++++++++++ tests/source/issue-6761.rs | 85 ------ .../associated-type-bounds-with-comments.rs | 287 ++++++++++++++++++ tests/target/issue-6761.rs | 90 ------ 5 files changed, 574 insertions(+), 183 deletions(-) create mode 100644 tests/source/associated-type-bounds-with-comments.rs create mode 100644 tests/target/associated-type-bounds-with-comments.rs diff --git a/src/items.rs b/src/items.rs index 1f4f97cd733..ab9ace9de20 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1769,19 +1769,19 @@ fn rewrite_ty( if let Some(bounds) = generic_bounds_opt { if !bounds.is_empty() { // 2 = `: ` - let shape = Shape::indented(indent, context.config); - let shape = shape.offset_left(result.len() + 2, span)?; + let item_shape = Shape::indented(indent, context.config); + let shape = item_shape.offset_left(result.len() + 2, span)?; let type_bounds = bounds.rewrite_result(context, shape)?; // The bounds rewrite only covers the bounds themselves, so comments // around the `:` would otherwise be dropped. Recover them on either // side of the colon, keeping the exact `: ` layout when there are none. let bounds_lo = bounds[0].span().lo(); - let colon_pos = context + let colon_lo = context .snippet_provider - .span_after(mk_sp(generics.span.hi(), bounds_lo), ":"); - let before_colon = mk_sp(generics.span.hi(), colon_pos - BytePos(1)); - let after_colon = mk_sp(colon_pos, bounds_lo); + .span_before(mk_sp(generics.span.hi(), bounds_lo), ":"); + let before_colon = mk_sp(generics.span.hi(), colon_lo); + let after_colon = mk_sp(colon_lo + BytePos(1), bounds_lo); if contains_comment(context.snippet(before_colon)) { result = combine_strs_with_missing_comments( @@ -1789,7 +1789,7 @@ fn rewrite_ty( &result, ":", before_colon, - shape, + item_shape, true, )?; } else { @@ -1802,7 +1802,7 @@ fn rewrite_ty( &result, &type_bounds, after_colon, - shape, + item_shape, true, )?; } else { diff --git a/tests/source/associated-type-bounds-with-comments.rs b/tests/source/associated-type-bounds-with-comments.rs new file mode 100644 index 00000000000..402358edf34 --- /dev/null +++ b/tests/source/associated-type-bounds-with-comments.rs @@ -0,0 +1,279 @@ +#![feature(associated_type_defaults)] + +// Exhaustive coverage of comments around associated-type bounds, keyed by +// position relative to the `:` / bounds / `where`, comment kind (line, +// block, multi-line line, multi-line block), and context (trait item with +// bounds, trait item without bounds, GAT, impl/free-alias shared path, +// bounds + RHS default). See #6761. +// +// Out of scope: a comment after bounds with no `where` clause at all (#6815) +// — that region has no span computed for it, so it needs separate handling. + +trait Bound {} +impl Bound for () {} + +// P1: between the ident/generics and the `:`. +trait P1 { + type A // line + : Bound + where + Self: Copy; + + type B /* inline */: Bound + where + Self: Copy; + + type C + // multi- + // line + : Bound + where + Self: Copy; + + type D + /* multi- + * line + */ + : Bound + where + Self: Copy; +} + +// P2: between the `:` and the first bound. +trait P2 { + type A: // line + Bound + where + Self: Copy; + + type B: /* inline */ Bound + where + Self: Copy; + + type C: + // multi- + // line + Bound + where + Self: Copy; + + type D: + /* multi- + * line + */ + Bound + where + Self: Copy; +} + +// P3: inside the bounds (generic args). Original #6761 repro. +trait P3 { + type A: Iterator< + // line + Item = Self, + > + where + Self: Copy; + + type B: Iterator< + /* inline */ + Item = Self, + > + where + Self: Copy; + + type C: Iterator< + // multi- + // line + Item = Self, + > + where + Self: Copy; + + type D: Iterator< + /* multi- + * line + */ + Item = Self, + > + where + Self: Copy; +} + +// P4: between two bounds. +trait P4 { + type A: Bound + // line + Bound + where + Self: Copy; + + type B: Bound + /* inline */ Bound + where + Self: Copy; + + type C: Bound + + // multi- + // line + Bound + where + Self: Copy; + + type D: Bound + + /* multi- + * line + */ + Bound + where + Self: Copy; +} + +// P5: after the last bound, before `where`. This is the duplication bug. +trait P5 { + type A: Bound + // line + where + Self: Copy; + + type B: Bound /* inline */ + where + Self: Copy; + + type C: Bound + // multi- + // line + where + Self: Copy; + + type D: Bound + /* multi- + * line + */ + where + Self: Copy; +} + +// P5, same-line trailing comment: the reviewer's exact input on #7014. +// rustfmt moves this onto its own line. That is `rewrite_where_keyword`'s +// shared behavior for every item kind (see tests/target/issue-3194.rs for +// struct/enum and type-alias-where-clauses-with-comments.rs for aliases), +// not something this fix introduces. Pinned here so the behavior is explicit. +trait P5SameLine { + type A: Iterator // trailing + where + Self: Copy; + + type B: Bound // trailing + where + Self: Copy; + + type C: Bound /* trailing */ + where + Self: Copy; +} + +// P5, no bounds: exercises the preserved `generics.span.hi()` default. +trait P5NoBounds { + type A + // line + where + Self: Copy; + + type B /* inline */ + where + Self: Copy; + + type C + // multi- + // line + where + Self: Copy; + + type D + /* multi- + * line + */ + where + Self: Copy; +} + +// Width: a colon comment must not wrap while the line still fits in +// max_width. `combine_strs_with_missing_comments` already measures the whole +// prefix, so it must be given the item shape, not the bounds-offset shape, +// or the prefix is charged twice and the line breaks early. +trait SomeModeratelyLongTraitName {} +trait ColonCommentWidth { + type AssociatedTypeWithLongName: /* comment */ SomeModeratelyLongTraitName + where + Self: Copy; +} + +// P6: after the `where` keyword, before the first predicate. +trait P6 { + type A: Bound + where + // line + Self: Copy; + + type B: Bound + where + /* inline */ + Self: Copy; + + type C: Bound + where + // multi- + // line + Self: Copy; + + type D: Bound + where + /* multi- + * line + */ + Self: Copy; +} + +// GAT with bounds: non-empty `generics.span`. +trait GatP5 { + type A: Bound + // line + where + U: Copy; + + type B: Bound /* inline */ + where + U: Copy; +} + +// Impl associated type: shared rewrite_ty/where-clause path. +trait ImplTarget { + type A + where + U: Copy; +} +struct S; +impl ImplTarget for S { + type A + // line, impl assoc type + where + U: Copy, + = Vec; +} + +// Free type alias: shared rewrite_ty/where-clause path. +type Free +// line, free alias +where + U: Copy, += Vec; + +// Bounds + RHS default, with comments (was Case 4, previously untested). +trait Rhs { + type A: Bound = () // line + where + Self: Copy; + + type B: Bound /* inline */ = () + where + Self: Copy; +} diff --git a/tests/source/issue-6761.rs b/tests/source/issue-6761.rs index 26734f707fc..f203ae340c2 100644 --- a/tests/source/issue-6761.rs +++ b/tests/source/issue-6761.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_defaults)] - // Case 1: exact issue repro (comment inside bounds + before-where clause). pub trait Trait { type I: Iterator< @@ -9,86 +7,3 @@ pub trait Trait { where Self: Copy; } - -// Case 2: comment between the bound and `where`. -trait Bar1 { - type B: Iterator // trailing - where - Self: Copy; -} - -// Case 3: a `/` appears in the bounds without being a comment. -trait Foo {} -trait Baz { - type C: Foo<{ 6 / 2 }> - where - Self: Copy; -} - -// Case 4: bound + RHS + trailing where clause (associated type default). -trait Bound {} -impl Bound for () {} -trait Qux { - type D: Bound = () where Self: Copy; -} - -// Case 5a: associated type in an impl block, no bounds (bounds have no -// effect on impl assoc types and are rejected by rustc), still exercises -// the shared rewrite_ty/where-clause path. -trait Gat { - type I - where - T: Copy; -} -struct S; -impl Gat for S { - type I - // comment before where - where - T: Copy, - = Vec; -} - -// Case 5b: free type alias, no bounds (bounds have no effect outside trait -// definitions), still exercises the shared rewrite_ty/where-clause path. -type E -// a free comment -where - T: Copy, -= Vec; - -// Case 6: no bounds + comment before `where` (guards the preserved -// generics.span.hi() default). -trait NoBounds { - type F // just a comment - where - Self: Copy; -} - -// Case 7: comments around the `:` must not be dropped. The bounds rewrite -// covers only the bounds themselves, so these are recovered separately. -trait AroundColon { - type G: /* after colon */ Bound - where - Self: Copy; - - type H: /* c1 */ Bound + Bound - where - Self: Copy; - - type I: // line comment after colon - Bound - where - Self: Copy; - - type J /* before colon */: Bound - where - Self: Copy; -} - -// Case 8: comment around the `:` on a generic associated type. -trait AroundColonGat { - type K: /* generics too */ Bound - where - U: Copy; -} diff --git a/tests/target/associated-type-bounds-with-comments.rs b/tests/target/associated-type-bounds-with-comments.rs new file mode 100644 index 00000000000..33d88416036 --- /dev/null +++ b/tests/target/associated-type-bounds-with-comments.rs @@ -0,0 +1,287 @@ +#![feature(associated_type_defaults)] + +// Exhaustive coverage of comments around associated-type bounds, keyed by +// position relative to the `:` / bounds / `where`, comment kind (line, +// block, multi-line line, multi-line block), and context (trait item with +// bounds, trait item without bounds, GAT, impl/free-alias shared path, +// bounds + RHS default). See #6761. +// +// Out of scope: a comment after bounds with no `where` clause at all (#6815) +// — that region has no span computed for it, so it needs separate handling. + +trait Bound {} +impl Bound for () {} + +// P1: between the ident/generics and the `:`. +trait P1 { + type A // line + : Bound + where + Self: Copy; + + type B /* inline */ : Bound + where + Self: Copy; + + type C + // multi- + // line + : Bound + where + Self: Copy; + + type D + /* multi- + * line + */ + : Bound + where + Self: Copy; +} + +// P2: between the `:` and the first bound. +trait P2 { + type A: // line + Bound + where + Self: Copy; + + type B: /* inline */ Bound + where + Self: Copy; + + type C: + // multi- + // line + Bound + where + Self: Copy; + + type D: + /* multi- + * line + */ + Bound + where + Self: Copy; +} + +// P3: inside the bounds (generic args). Original #6761 repro. +trait P3 { + type A: Iterator< + // line + Item = Self, + > + where + Self: Copy; + + type B: Iterator + where + Self: Copy; + + type C: Iterator< + // multi- + // line + Item = Self, + > + where + Self: Copy; + + type D: Iterator< + /* multi- + * line + */ + Item = Self, + > + where + Self: Copy; +} + +// P4: between two bounds. +trait P4 { + type A: Bound + + // line + Bound + where + Self: Copy; + + type B: Bound + /* inline */ Bound + where + Self: Copy; + + type C: Bound + + + // multi- + // line + Bound + where + Self: Copy; + + type D: Bound + + + /* multi- + * line + */ + Bound + where + Self: Copy; +} + +// P5: after the last bound, before `where`. This is the duplication bug. +trait P5 { + type A: Bound + // line + where + Self: Copy; + + type B: Bound + /* inline */ + where + Self: Copy; + + type C: Bound + // multi- + // line + where + Self: Copy; + + type D: Bound + /* multi- + * line + */ + where + Self: Copy; +} + +// P5, same-line trailing comment: the reviewer's exact input on #7014. +// rustfmt moves this onto its own line. That is `rewrite_where_keyword`'s +// shared behavior for every item kind (see tests/target/issue-3194.rs for +// struct/enum and type-alias-where-clauses-with-comments.rs for aliases), +// not something this fix introduces. Pinned here so the behavior is explicit. +trait P5SameLine { + type A: Iterator + // trailing + where + Self: Copy; + + type B: Bound + // trailing + where + Self: Copy; + + type C: Bound + /* trailing */ + where + Self: Copy; +} + +// P5, no bounds: exercises the preserved `generics.span.hi()` default. +trait P5NoBounds { + type A + // line + where + Self: Copy; + + type B + /* inline */ + where + Self: Copy; + + type C + // multi- + // line + where + Self: Copy; + + type D + /* multi- + * line + */ + where + Self: Copy; +} + +// Width: a colon comment must not wrap while the line still fits in +// max_width. `combine_strs_with_missing_comments` already measures the whole +// prefix, so it must be given the item shape, not the bounds-offset shape, +// or the prefix is charged twice and the line breaks early. +trait SomeModeratelyLongTraitName {} +trait ColonCommentWidth { + type AssociatedTypeWithLongName: /* comment */ SomeModeratelyLongTraitName + where + Self: Copy; +} + +// P6: after the `where` keyword, before the first predicate. +trait P6 { + type A: Bound + where + // line + Self: Copy; + + type B: Bound + where + /* inline */ + Self: Copy; + + type C: Bound + where + // multi- + // line + Self: Copy; + + type D: Bound + where + /* multi- + * line + */ + Self: Copy; +} + +// GAT with bounds: non-empty `generics.span`. +trait GatP5 { + type A: Bound + // line + where + U: Copy; + + type B: Bound + /* inline */ + where + U: Copy; +} + +// Impl associated type: shared rewrite_ty/where-clause path. +trait ImplTarget { + type A + where + U: Copy; +} +struct S; +impl ImplTarget for S { + type A + // line, impl assoc type + where + U: Copy, + = Vec; +} + +// Free type alias: shared rewrite_ty/where-clause path. +type Free +// line, free alias +where + U: Copy, += Vec; + +// Bounds + RHS default, with comments (was Case 4, previously untested). +trait Rhs { + type A: Bound + = () + // line + where + Self: Copy; + + type B: Bound /* inline */ = () + where + Self: Copy; +} diff --git a/tests/target/issue-6761.rs b/tests/target/issue-6761.rs index 9e2d412a4a4..f203ae340c2 100644 --- a/tests/target/issue-6761.rs +++ b/tests/target/issue-6761.rs @@ -1,5 +1,3 @@ -#![feature(associated_type_defaults)] - // Case 1: exact issue repro (comment inside bounds + before-where clause). pub trait Trait { type I: Iterator< @@ -9,91 +7,3 @@ pub trait Trait { where Self: Copy; } - -// Case 2: comment between the bound and `where`. -trait Bar1 { - type B: Iterator - // trailing - where - Self: Copy; -} - -// Case 3: a `/` appears in the bounds without being a comment. -trait Foo {} -trait Baz { - type C: Foo<{ 6 / 2 }> - where - Self: Copy; -} - -// Case 4: bound + RHS + trailing where clause (associated type default). -trait Bound {} -impl Bound for () {} -trait Qux { - type D: Bound - = () - where - Self: Copy; -} - -// Case 5a: associated type in an impl block, no bounds (bounds have no -// effect on impl assoc types and are rejected by rustc), still exercises -// the shared rewrite_ty/where-clause path. -trait Gat { - type I - where - T: Copy; -} -struct S; -impl Gat for S { - type I - // comment before where - where - T: Copy, - = Vec; -} - -// Case 5b: free type alias, no bounds (bounds have no effect outside trait -// definitions), still exercises the shared rewrite_ty/where-clause path. -type E -// a free comment -where - T: Copy, -= Vec; - -// Case 6: no bounds + comment before `where` (guards the preserved -// generics.span.hi() default). -trait NoBounds { - type F - // just a comment - where - Self: Copy; -} - -// Case 7: comments around the `:` must not be dropped. The bounds rewrite -// covers only the bounds themselves, so these are recovered separately. -trait AroundColon { - type G: /* after colon */ Bound - where - Self: Copy; - - type H: /* c1 */ Bound + Bound - where - Self: Copy; - - type I: // line comment after colon - Bound - where - Self: Copy; - - type J /* before colon */ : Bound - where - Self: Copy; -} - -// Case 8: comment around the `:` on a generic associated type. -trait AroundColonGat { - type K: /* generics too */ Bound - where - U: Copy; -} From bf91d830d059a6a4202b33a04de18920389aeb29 Mon Sep 17 00:00:00 2001 From: saberoueslati Date: Sun, 23 Aug 2026 00:49:04 +0100 Subject: [PATCH 3/3] test: drop compile-only scaffolding from bounds fixture --- tests/source/associated-type-bounds-with-comments.rs | 10 ---------- tests/target/associated-type-bounds-with-comments.rs | 10 ---------- 2 files changed, 20 deletions(-) diff --git a/tests/source/associated-type-bounds-with-comments.rs b/tests/source/associated-type-bounds-with-comments.rs index 402358edf34..d6310b89cdf 100644 --- a/tests/source/associated-type-bounds-with-comments.rs +++ b/tests/source/associated-type-bounds-with-comments.rs @@ -9,9 +9,6 @@ // Out of scope: a comment after bounds with no `where` clause at all (#6815) // — that region has no span computed for it, so it needs separate handling. -trait Bound {} -impl Bound for () {} - // P1: between the ident/generics and the `:`. trait P1 { type A // line @@ -200,7 +197,6 @@ trait P5NoBounds { // max_width. `combine_strs_with_missing_comments` already measures the whole // prefix, so it must be given the item shape, not the bounds-offset shape, // or the prefix is charged twice and the line breaks early. -trait SomeModeratelyLongTraitName {} trait ColonCommentWidth { type AssociatedTypeWithLongName: /* comment */ SomeModeratelyLongTraitName where @@ -246,12 +242,6 @@ trait GatP5 { } // Impl associated type: shared rewrite_ty/where-clause path. -trait ImplTarget { - type A - where - U: Copy; -} -struct S; impl ImplTarget for S { type A // line, impl assoc type diff --git a/tests/target/associated-type-bounds-with-comments.rs b/tests/target/associated-type-bounds-with-comments.rs index 33d88416036..a8c25f03a33 100644 --- a/tests/target/associated-type-bounds-with-comments.rs +++ b/tests/target/associated-type-bounds-with-comments.rs @@ -9,9 +9,6 @@ // Out of scope: a comment after bounds with no `where` clause at all (#6815) // — that region has no span computed for it, so it needs separate handling. -trait Bound {} -impl Bound for () {} - // P1: between the ident/generics and the `:`. trait P1 { type A // line @@ -205,7 +202,6 @@ trait P5NoBounds { // max_width. `combine_strs_with_missing_comments` already measures the whole // prefix, so it must be given the item shape, not the bounds-offset shape, // or the prefix is charged twice and the line breaks early. -trait SomeModeratelyLongTraitName {} trait ColonCommentWidth { type AssociatedTypeWithLongName: /* comment */ SomeModeratelyLongTraitName where @@ -252,12 +248,6 @@ trait GatP5 { } // Impl associated type: shared rewrite_ty/where-clause path. -trait ImplTarget { - type A - where - U: Copy; -} -struct S; impl ImplTarget for S { type A // line, impl assoc type