From 1f0a773c1c05807c1622d644261e075f5b511984 Mon Sep 17 00:00:00 2001 From: Kevin Ji <1146876+kevinji@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:46:17 -0700 Subject: [PATCH] Remove newlines in where clauses for v2 Fixes #5655. --- src/items.rs | 4 +++- tests/source/issue-5655/one.rs | 9 +++++++++ tests/source/issue-5655/two.rs | 9 +++++++++ tests/target/issue-5655/one.rs | 9 +++++++++ tests/target/issue-5655/two.rs | 8 ++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-5655/one.rs create mode 100644 tests/source/issue-5655/two.rs create mode 100644 tests/target/issue-5655/one.rs create mode 100644 tests/target/issue-5655/two.rs diff --git a/src/items.rs b/src/items.rs index fd4e08ed403..da5274dda83 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2998,10 +2998,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::>(), &fmt) } diff --git a/tests/source/issue-5655/one.rs b/tests/source/issue-5655/one.rs new file mode 100644 index 00000000000..1758ec56f8b --- /dev/null +++ b/tests/source/issue-5655/one.rs @@ -0,0 +1,9 @@ +// rustfmt-version: One + +fn foo(_: 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 00000000000..e37ebbea8af --- /dev/null +++ b/tests/source/issue-5655/two.rs @@ -0,0 +1,9 @@ +// rustfmt-version: Two + +fn foo(_: 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 00000000000..1758ec56f8b --- /dev/null +++ b/tests/target/issue-5655/one.rs @@ -0,0 +1,9 @@ +// rustfmt-version: One + +fn foo(_: 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 00000000000..14fbc3d1321 --- /dev/null +++ b/tests/target/issue-5655/two.rs @@ -0,0 +1,8 @@ +// rustfmt-version: Two + +fn foo(_: T) +where + T: std::fmt::Debug, + T: std::fmt::Display, +{ +}