about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/items.rs10
-rw-r--r--tests/target/impl.rs5
2 files changed, 11 insertions, 4 deletions
diff --git a/src/items.rs b/src/items.rs
index edb5a5b629a..d6488ffd141 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -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(" {}");
diff --git a/tests/target/impl.rs b/tests/target/impl.rs
index f37fbcf1fcb..10de0ecde56 100644
--- a/tests/target/impl.rs
+++ b/tests/target/impl.rs
@@ -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 {}