Don't format fn keywords when not selected with --file-lines#6886
Don't format fn keywords when not selected with --file-lines#6886randomPoison wants to merge 8 commits intorust-lang:mainfrom
Conversation
That avoids the need to scan backwards for a non-whitespace character
|
Going to mark this as |
|
Hm, I would think that these changes are pretty orthogonal to any decisions about how exactly to format the function keywords, since this is just determining if those keywords are selected with Can you point me to where the relevant work/discussion is happening? I'd like to follow along with it so I can figure out how it'll interact with Also, do you know if there are any related discussions that would impact incorporating |
Allow
--file-linesto skip formatting the leading keywords for a function definition (pub,unsafe,extern, etc.) when not selected. Part of #6868.The behavior I chose is to treat all of the keywords before
fnas a single unit: We either format all of them, or we format none of them. This seemed like the most reasonable approach because rustfmt will always put all of the keywords on one line, so it didn't make sense to try to support formatting only a couple of the keywords. Treating them all as an indivisible block also keeps the logic simpler here, since there's only one span we have to check for.I also made a minor tweak to
span_before_lastto allow it to handle multi-character needles. Previously it was only used to find single character needles, and was hardcoding the length of the needle as 1. I wanted to use it to find the span before thefnkeyword, so I've updated it to take the actual length of the needle into account.