You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
I noticed rustfmt refused to reindent a single line of a multiline match expression unless the --file-lines range included both the start of the match and the misindented line.
Here is a minimal reproduction:
fnmain(){match1{// Line 2 is the start of the match1 => (),2 => {let _ = ();// Line 5 isn't indented}}}
# This should reindent line 5, but it does nothing
rustfmt +nightly --unstable-features --file-lines '[{"file": "a.rs", "range": [5, 5]}]' a.rs --check
# This does reindent line 5
rustfmt +nightly --unstable-features --file-lines '[{"file": "a.rs", "range": [2, 5]}]' a.rs --check
version rustfmt 1.4.12-nightly (9f53665f 2020-02-10)
Imagine the following statement in which one line is wrongly indented:
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
The text was updated successfully, but these errors were encountered: