Skip to content

Commit

Permalink
Fixes comma added to comment in where-clause
Browse files Browse the repository at this point in the history
  • Loading branch information
GambitingMan authored and calebcartwright committed Nov 2, 2023
1 parent 041f113 commit 8d2c415
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,13 +831,15 @@ pub(crate) fn format_impl(

if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? {
result.push_str(&where_clause_str);
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
// if the where_clause contains extra comments AND
// there is only one where-clause predicate
// recover the suppressed comma in single line where_clause formatting
if where_clause_str.contains('\n') {
// If there is only one where-clause predicate
// and the where-clause spans multiple lines,
// then recover the suppressed comma in single line where-clause formatting
if generics.where_clause.predicates.len() == 1 {
result.push(',');
}
}
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
result.push_str(&format!("{sep}{{{sep}}}"));
} else {
result.push_str(" {}");
Expand Down
5 changes: 5 additions & 0 deletions tests/target/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ where
{
}

// #5941
impl T where (): Clone // Should not add comma to comment
{
}

// #1823
default impl Trait for X {}
default unsafe impl Trait for Y {}
Expand Down

0 comments on commit 8d2c415

Please sign in to comment.