Skip to content

Commit 8d2c415

Browse files
GambitingMancalebcartwright
authored andcommitted
Fixes comma added to comment in where-clause
1 parent 041f113 commit 8d2c415

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/items.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,13 +831,15 @@ pub(crate) fn format_impl(
831831

832832
if is_impl_single_line(context, items.as_slice(), &result, &where_clause_str, item)? {
833833
result.push_str(&where_clause_str);
834-
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
835-
// if the where_clause contains extra comments AND
836-
// there is only one where-clause predicate
837-
// recover the suppressed comma in single line where_clause formatting
834+
if where_clause_str.contains('\n') {
835+
// If there is only one where-clause predicate
836+
// and the where-clause spans multiple lines,
837+
// then recover the suppressed comma in single line where-clause formatting
838838
if generics.where_clause.predicates.len() == 1 {
839839
result.push(',');
840840
}
841+
}
842+
if where_clause_str.contains('\n') || last_line_contains_single_line_comment(&result) {
841843
result.push_str(&format!("{sep}{{{sep}}}"));
842844
} else {
843845
result.push_str(" {}");

tests/target/impl.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ where
3232
{
3333
}
3434

35+
// #5941
36+
impl T where (): Clone // Should not add comma to comment
37+
{
38+
}
39+
3540
// #1823
3641
default impl Trait for X {}
3742
default unsafe impl Trait for Y {}

0 commit comments

Comments
 (0)