Repository: rust-lang/rustfmt (rust)

Issue:
Empty lines in where-clause
I would expect the empty line between the `T: std::fmt::Debug` and `T: std::fmt::Display` lines to be removed by rustfmt, but it isn't:
```rust
fn foo<T>(_: T)
where
    T: std::fmt::Debug,

    T: std::fmt::Display,
{
}
```
At least not by the `rustfmt 1.5.1-stable (69f9c33d 2022-12-12)` version.

I'm sorry if it is a duplicate, but I haven't been able to find any related issues.

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_ASSIGN_START -->

<!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"naosense"}$$TRIAGEBOT_ASSIGN_DATA_END -->

<!-- TRIAGEBOT_ASSIGN_END -->
<!-- TRIAGEBOT_END -->

Pull request:
Remove newlines in where clauses for v2
Fixes #5655.

Closes #5679. This PR is an alternative that feature-gates the fix per the [comment in that PR](https://github.com/rust-lang/rustfmt/pull/5679#discussion_r1091116166).

Patch:
diff --git a/src/items.rs b/src/items.rs
index 1f4a1421..4d82e192 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -2996,10 +2996,12 @@ fn rewrite_bounds_on_where_clause(
         DefinitiveListTactic::Vertical
     };
 
+    let preserve_newline = context.config.version() == Version::One;
+
     let fmt = ListFormatting::new(shape, context.config)
         .tactic(shape_tactic)
         .trailing_separator(comma_tactic)
-        .preserve_newline(true);
+        .preserve_newline(preserve_newline);
     write_list(&items.collect::<Vec<_>>(), &fmt)
 }
 


Test patch:
diff --git a/tests/source/issue-5655/one.rs b/tests/source/issue-5655/one.rs
new file mode 100644
index 00000000..1758ec56
--- /dev/null
+++ b/tests/source/issue-5655/one.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: One
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/source/issue-5655/two.rs b/tests/source/issue-5655/two.rs
new file mode 100644
index 00000000..e37ebbea
--- /dev/null
+++ b/tests/source/issue-5655/two.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: Two
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/target/issue-5655/one.rs b/tests/target/issue-5655/one.rs
new file mode 100644
index 00000000..1758ec56
--- /dev/null
+++ b/tests/target/issue-5655/one.rs
@@ -0,0 +1,9 @@
+// rustfmt-version: One
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+
+    T: std::fmt::Display,
+{
+}
diff --git a/tests/target/issue-5655/two.rs b/tests/target/issue-5655/two.rs
new file mode 100644
index 00000000..14fbc3d1
--- /dev/null
+++ b/tests/target/issue-5655/two.rs
@@ -0,0 +1,8 @@
+// rustfmt-version: Two
+
+fn foo<T>(_: T)
+where
+    T: std::fmt::Debug,
+    T: std::fmt::Display,
+{
+}