file-lines can't partially format where clauses
@Souradip121 is already working on this.
Since Apr 21, 2026.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
With the --file-lines option I'd expect to be able to partially format a where clause, e.g. only format one or two lines of trait bounds, without modifying any unselected lines. Currently any attempt to partially format a where clause will reformat the whole thing.
Summary
For the following Rust code in test.rs:
fn generic_fn<T>() where
T: Clone,
T: Copy,
T: Default,
{
println!("a");
}
I'd like to format just the last trait bound in the where clause with rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[4,4]}]' test.rs, without modifying any other lines.
Expected behavior
fn generic_fn<T>() where
T: Clone,
T: Copy,
T: Default,
{
println!("a");
}
Actual behavior
fn generic_fn<T>()
where
T: Clone,
T: Copy,
T: Default,
{
println!("a");
}
Configuration
rustfmt cli options used:
rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[4,4]}]' test.rs
Meta
Split off from https://github.com/rust-lang/rustfmt/issues/6868 because where clauses show up in other places than just function signatures. Similar to that issue, the issue here is that rewrite_where_clause doesn't currently try to handle the file-lines config at all. It'll need to be extended to check the selected lines and preserve the original text for lines outside the selected range.
This should be added as a blocker for https://github.com/rust-lang/rustfmt/issues/3397.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.