Fix wrong indenting with hard tabs in binop pairs#6883
Draft
matthewhughes934 wants to merge 1 commit intorust-lang:mainfrom
Draft
Fix wrong indenting with hard tabs in binop pairs#6883matthewhughes934 wants to merge 1 commit intorust-lang:mainfrom
matthewhughes934 wants to merge 1 commit intorust-lang:mainfrom
Conversation
When rewriting pairs of multi-line binary operations, we would check the
length of a line to see if we can snuggle the current line into the
previous one. We compute the length of the previous line using
`last_line_width` which is not aware of indentation widths (i.e.
`config.tab_spaces`), so if we were formatting something like:
if some_long_name {
foo
} | if some_other_name {
bar
}
Then when we get to the line for `| if some_other_name {` we check the
previous line, which is:
* `\s\s\s\s\s\s\s\s}' if we are not using hard tabs (and 1 tab = 4
spaces), and
* `\t\t}` if we are using hard-tabs
`last_line_width` would return 9 for the first one, and 3 for the
second. Meaning if we're using hard tabs we could conclude that it
should fit on the previous line, leading to inconsistent behaviour
between the two.
To fix this, create a version of `last_line_width` that is aware of
`config.tab_spaces`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: opening as draft for a discussion. I'm not sure about the approach since there might be wide implications for all other callers of
last_line_widthWhen rewriting pairs of multi-line binary operations, we would check the length of a line to see if we can snuggle the current line into the previous one. We compute the length of the previous line using
last_line_widthwhich is not aware of indentation widths (i.e.config.tab_spaces), so if we were formatting something like:Then when we get to the line for
| if some_other_name {we check the previous line, which is:\t\t}if we are using hard-tabslast_line_widthwould return 9 for the first one, and 3 for the second. Meaning if we're using hard tabs we could conclude that it should fit on the previous line, leading to inconsistent behaviour between the two.To fix this, create a version of
last_line_widththat is aware ofconfig.tab_spaces.