Skip to content
Merged
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
20 changes: 11 additions & 9 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3121,8 +3121,13 @@ fn rewrite_where_keyword(

let (span_before, span_after) =
missing_span_before_after_where(span_end_before_where, predicates, where_span);
let (comment_before, comment_after) =
rewrite_comments_before_after_where(context, span_before, span_after, shape)?;
let (comment_before, comment_after) = rewrite_comments_before_after_where(
context,
span_before,
span_after,
block_shape,
clause_shape,
)?;

let starting_newline = match where_clause_option.snuggle {
WhereClauseSpace::Space if comment_before.is_empty() => Cow::from(" "),
Expand Down Expand Up @@ -3316,14 +3321,11 @@ fn rewrite_comments_before_after_where(
context: &RewriteContext<'_>,
span_before_where: Span,
span_after_where: Span,
shape: Shape,
before_shape: Shape,
after_shape: Shape,
) -> Result<(String, String), RewriteError> {
let before_comment = rewrite_missing_comment(span_before_where, shape, context)?;
let after_comment = rewrite_missing_comment(
span_after_where,
shape.block_indent(context.config.tab_spaces()),
context,
)?;
let before_comment = rewrite_missing_comment(span_before_where, before_shape, context)?;
let after_comment = rewrite_missing_comment(span_after_where, after_shape, context)?;
Ok((before_comment, after_comment))
}

Expand Down
29 changes: 29 additions & 0 deletions tests/source/where-clause-comment-wrap-issue-7148.rs
Comment thread
dbaileychess marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// rustfmt-wrap_comments: true
// rustfmt-max_width: 100
// rustfmt-comment_width: 100

// Comments between `where` and the first predicate should be formatted using
// the full column budget rather than a budget derived from the header width.
impl<T> SomeTrait for LongTypeName<T>
where
// A long comment line between where and the first clause that fits within max width limit
// already. So no additional wrapping should occur.
T: SomeTrait,

// A long comment line between where and the first clause that fits within max width limit
// already. So no additional wrapping should occur.
T: OtherTrait,
Comment thread
dbaileychess marked this conversation as resolved.
{
}

// Comments between `where` and the first predicate should be formatted using
// the full column budget rather than a budget derived from the header width.
impl<T> SomeOtherTrait for LongTypeName<T>
where
// A long comment line between where and the first clause that doesn't fit within max width limit already. So additional wrapping should occur.
T: SomeTrait,

// A long comment line between where and the first clause that doesn't fit within max width limit already. So additional wrapping should occur.
T: OtherTrait,
{
}
31 changes: 31 additions & 0 deletions tests/target/where-clause-comment-wrap-issue-7148.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// rustfmt-wrap_comments: true
// rustfmt-max_width: 100
// rustfmt-comment_width: 100

// Comments between `where` and the first predicate should be formatted using
// the full column budget rather than a budget derived from the header width.
impl<T> SomeTrait for LongTypeName<T>
where
// A long comment line between where and the first clause that fits within max width limit
// already. So no additional wrapping should occur.
T: SomeTrait,

// A long comment line between where and the first clause that fits within max width limit
// already. So no additional wrapping should occur.
T: OtherTrait,
{
}

// Comments between `where` and the first predicate should be formatted using
// the full column budget rather than a budget derived from the header width.
impl<T> SomeOtherTrait for LongTypeName<T>
where
// A long comment line between where and the first clause that doesn't fit within max width
// limit already. So additional wrapping should occur.
T: SomeTrait,

// A long comment line between where and the first clause that doesn't fit within max width
// limit already. So additional wrapping should occur.
T: OtherTrait,
{
}
Loading