rust-lang / rust-lang/rustfmt

file-lines do not reformat parts of a multi-line statement

Open
#4,053 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-call-chains only-with-option UO-file_lines
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Imagine the following statement in which one line is wrongly indented:

let diff = repo
.diff_tree_to_workdir(Some(&head), Some(&mut diff_options))
    .unwrap();

I now specify only the second line in my --file-lines.

What I expect to happen
The second line becomes correctly indented to match the same column as the .unwrap().

What actually happens
Nothing. The line is ignored because it is part of a larger statement.

Why this is a problem
I have a use case where a script uses git and --file-lines to only format lines which where changed in a specific commit. This script fails when someone just edits parts of a larger statement because the line is not formatted then. Adding more context to the range is also not viable because then lines are formatted that weren't touched in the commit.

#3397

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example with rustfmt and the --file-lines option, using the multi-line statement shown in the issue. Trace how selected lines are handled when they belong to a larger statement; done means the selected line is reformatted without formatting untouched lines in the same statement.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.