Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,35 @@ This option is currently ignored for stdin (`@generated` in stdin is ignored.)
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))

## `keep_newline_in_where_clause`

- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No (tracking issue: [#5655](https://github.com/rust-lang/rustfmt/issues/5655))

#### `true` (default):

```rust
fn foo<T>(_: T)
where
T: std::fmt::Debug,

T: std::fmt::Display,
{
}
```

#### `false`

```rust
fn foo<T>(_: T)
where
T: std::fmt::Debug,
T: std::fmt::Display,
{
}
```

## `format_macro_matchers`

Format the metavariable matching patterns in macros.
Expand Down
2 changes: 2 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ create_config! {
"Write an item and its attribute on the same line \
if their combined width is below a threshold";
format_generated_files: bool, true, false, "Format generated files";
keep_newline_in_where_clause: bool, true, false, "Keep newline in where clause";

// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
Expand Down Expand Up @@ -667,6 +668,7 @@ edition = "2015"
version = "One"
inline_attribute_width = 0
format_generated_files = true
keep_newline_in_where_clause = true
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
Expand Down
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2886,7 +2886,7 @@ fn rewrite_bounds_on_where_clause(
let fmt = ListFormatting::new(shape, context.config)
.tactic(shape_tactic)
.trailing_separator(comma_tactic)
.preserve_newline(true);
.preserve_newline(context.config.keep_newline_in_where_clause());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebcartwright originally I thought it would be best to let users configure this, but maybe we'd rather just version gate the fix?

write_list(&items.collect::<Vec<_>>(), &fmt)
}

Expand Down
7 changes: 7 additions & 0 deletions tests/source/issue-5655/keep_newline_in_where_clause_false.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// keep_newline_in_where_clause: false
fn foo<T>(_: T)
where
T: std::fmt::Debug,
T: std::fmt::Display,
{
}
8 changes: 8 additions & 0 deletions tests/source/issue-5655/keep_newline_in_where_clause_true.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// keep_newline_in_where_clause: true
fn foo<T>(_: T)
where
T: std::fmt::Debug,

T: std::fmt::Display,
{
}
7 changes: 7 additions & 0 deletions tests/target/issue-5655/keep_newline_in_where_clause_false.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// keep_newline_in_where_clause: false
fn foo<T>(_: T)
where
T: std::fmt::Debug,
T: std::fmt::Display,
{
}
8 changes: 8 additions & 0 deletions tests/target/issue-5655/keep_newline_in_where_clause_true.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// keep_newline_in_where_clause: true
fn foo<T>(_: T)
where
T: std::fmt::Debug,

T: std::fmt::Display,
{
}