Skip to content

Commit 37257b4

Browse files
committed
style-guide: Clarify version-sorting
Every time we apply version-sorting, we also say to sort non-lowercase before lowercase. This seems likely to be what we'll want for future sorting, as well. For simplicity, just incorporate that into the definition, "unless otherwise specified".
1 parent f00f850 commit 37257b4

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

Diff for: src/doc/style-guide/src/README.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ fn baz() {}
117117
In various cases, the default Rust style specifies to sort things. If not
118118
otherwise specified, such sorting should be "version sorting", which ensures
119119
that (for instance) `x8` comes before `x16` even though the character `1` comes
120-
before the character `8`. (If not otherwise specified, version-sorting is
121-
lexicographical.)
120+
before the character `8`.
122121

123122
For the purposes of the Rust style, to compare two strings for version-sorting:
124123

@@ -132,12 +131,13 @@ For the purposes of the Rust style, to compare two strings for version-sorting:
132131
these strings, treat the chunks as equal (moving on to the next chunk) but
133132
remember which string had more leading zeroes.
134133
- To compare two chunks if both are not numeric, compare them by Unicode
135-
character lexicographically, except that `_` (underscore) sorts immediately
136-
after ` ` (space) but before any other character. (This treats underscore as
137-
a word separator, as commonly used in identifiers.)
138-
- If the use of version sorting specifies further modifiers, such as sorting
139-
non-lowercase before lowercase, apply those modifiers to the lexicographic
140-
sort in this step.
134+
character lexicographically, with two exceptions:
135+
- `_` (underscore) sorts immediately after ` ` (space) but before any other
136+
character. (This treats underscore as a word separator, as commonly used in
137+
identifiers.)
138+
- Unless otherwise specified, version-sorting should sort non-lowercase
139+
characters (characters that can start an `UpperCamelCase` identifier)
140+
before lowercase characters.
141141
- If the comparison reaches the end of the string and considers each pair of
142142
chunks equal:
143143
- If one of the numeric comparisons noted the earliest point at which one
@@ -157,7 +157,17 @@ leading zeroes.
157157

158158
As an example, version-sorting will sort the following strings in the order
159159
given:
160-
- `_ZYWX`
160+
- `_ZYXW`
161+
- `_abcd`
162+
- `A2`
163+
- `ABCD`
164+
- `Z_YXW`
165+
- `ZY_XW`
166+
- `ZY_XW`
167+
- `ZYXW`
168+
- `ZYXW_`
169+
- `a1`
170+
- `abcd`
161171
- `u_zzz`
162172
- `u8`
163173
- `u16`
@@ -190,11 +200,7 @@ given:
190200
- `x86_64`
191201
- `x86_128`
192202
- `x87`
193-
- `Z_YWX`
194-
- `ZY_WX`
195-
- `ZYW_X`
196-
- `ZYWX`
197-
- `ZYWX_`
203+
- `zyxw`
198204

199205
### [Module-level items](items.md)
200206

Diff for: src/doc/style-guide/src/items.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,8 @@ foo::{
489489
A *group* of imports is a set of imports on the same or sequential lines. One or
490490
more blank lines or other items (e.g., a function) separate groups of imports.
491491

492-
Within a group of imports, imports must be version-sorted, except that
493-
non-lowercase characters (characters that can start an `UpperCamelCase`
494-
identifier) must be sorted before lowercase characters. Groups of imports must
495-
not be merged or re-ordered.
492+
Within a group of imports, imports must be version-sorted. Groups of imports
493+
must not be merged or re-ordered.
496494

497495
E.g., input:
498496

@@ -520,9 +518,7 @@ re-ordering.
520518
### Ordering list import
521519

522520
Names in a list import must be version-sorted, except that:
523-
- `self` and `super` always come first if present,
524-
- non-lowercase characters (characters that can start an `UpperCamelCase`
525-
identifier) must be sorted before lowercase characters, and
521+
- `self` and `super` always come first if present, and
526522
- groups and glob imports always come last if present.
527523

528524
This applies recursively. For example, `a::*` comes before `b::a` but `a::b`

0 commit comments

Comments
 (0)