file-lines modifies unselected fn signature lines when fn body is selected
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
If the opening brace of a function is on a separate line, then when partially formatting the body of the function with --file-lines the opening brace can be moved to the previous line, even if neither of those lines were selected.
Summary
Consider the following file test.rs which defines a function where the opening brace of the function is on its own line:
fn main()
{
println!("weeeeee");
println!("weeeeee");
println!("weeeeee");
}
I would like to use --file-lines '[{"file":"test.rs","range":[5,5]}]' to format just the last line of the function.
Expected Behavior
Only the selected line is formatted:
fn main()
{
println!("weeeeee");
println!("weeeeee");
println!("weeeeee");
}
Actual Behavior
The selected line, the preceding line, and the first two lines of the function are modified:
fn main() {
println!("weeeeee");
println!("weeeeee");
println!("weeeeee");
}
I have a separate issue up for the fact that line 4 is also modified (https://github.com/rust-lang/rustfmt/issues/6863), this issue is meant to focus on the fact that lines 1-2 are modified even though they are outside the selected range.
Configuration
rustfmt cli options used:
rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[5,5]}]' test.rs
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.
Research direction
Reproduce the issue with the shown test.rs input and rustfmt --unstable-features --file-lines command. Trace the --file-lines range handling and ensure formatting the selected line does not modify the unselected function signature or opening-brace lines; verify the result against the expected output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100