Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 14 additions & 2 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3136,7 +3136,13 @@ fn rewrite_bounds_on_where_clause(
",",
|pred| pred.span().lo(),
|pred| pred.span().hi(),
|pred| pred.rewrite_result(context, shape),
|pred| {
if out_of_file_lines_range!(context, pred.span()) {
Ok(context.snippet(pred.span()).to_owned())
} else {
pred.rewrite_result(context, shape)
}
},
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi Apr 21, 2026

Choose a reason for hiding this comment

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

Instead of doing this check here, I'm wondering if we could move this logic to the Iterator impl for ListItems. It will likely require us to pass the whole RewriteContext to itemize_list instead of just the snippet_provider, but that should be fine.

Moving this check there means that we wouldn't need to duplicateif out_of_file_lines_range! every time we use itemize_list, and it means that you'd actually fix things for other code paths that use this pattern.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Alright, made a commit, kindly check.

span_start,
span_end,
false,
Expand Down Expand Up @@ -3222,7 +3228,13 @@ fn rewrite_where_clause(
",",
|pred| pred.span().lo(),
|pred| pred.span().hi(),
|pred| pred.rewrite_result(context, Shape::legacy(budget, offset)),
|pred| {
if out_of_file_lines_range!(context, pred.span()) {
Ok(context.snippet(pred.span()).to_owned())
} else {
pred.rewrite_result(context, Shape::legacy(budget, offset))
}
},
span_start,
span_end,
false,
Expand Down
9 changes: 9 additions & 0 deletions tests/source/file-lines-where-clause.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-file_lines: [{"file":"tests/source/file-lines-where-clause.rs","range":[5,5]}]

fn foo<T, U, V>()
where
T: Clone + Debug,
U: Copy,
V: Default,
Copy link
Copy Markdown
Contributor

@randomPoison randomPoison Apr 21, 2026

Choose a reason for hiding this comment

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

A minor note: The way this test is written it's a bit hard to see what exactly is changing between the source file and target file, since only a single space is changing. I'd suggest changing the input file so that the bad formatting is more obvious, such that it's easier to tell at a glance what the test covers:

fn foo<T, U, V>()
where
    T     :     Clone      +     Debug,
    U    :       Copy,
    V   :        Default,

Would then become

fn foo<T, U, V>()
where
    T: Clone + Debug,
    U    :       Copy,
    V   :        Default,

View changes since the review

{
}
9 changes: 9 additions & 0 deletions tests/target/file-lines-where-clause.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-file_lines: [{"file":"tests/source/file-lines-where-clause.rs","range":[5,5]}]

fn foo<T, U, V>()
where
T: Clone + Debug,
U: Copy,
V: Default,
{
}
Loading