Skip to content

file-lines can't partially format where clauses #6872

@randomPoison

Description

@randomPoison

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 #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 #3397.

Metadata

Metadata

Assignees

Labels

C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEUO-file_linesUnstable option: file_lines

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions