mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
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".
This commit is contained in:
parent
f00f850919
commit
37257b45e9
@ -117,8 +117,7 @@ fn baz() {}
|
|||||||
In various cases, the default Rust style specifies to sort things. If not
|
In various cases, the default Rust style specifies to sort things. If not
|
||||||
otherwise specified, such sorting should be "version sorting", which ensures
|
otherwise specified, such sorting should be "version sorting", which ensures
|
||||||
that (for instance) `x8` comes before `x16` even though the character `1` comes
|
that (for instance) `x8` comes before `x16` even though the character `1` comes
|
||||||
before the character `8`. (If not otherwise specified, version-sorting is
|
before the character `8`.
|
||||||
lexicographical.)
|
|
||||||
|
|
||||||
For the purposes of the Rust style, to compare two strings for version-sorting:
|
For the purposes of the Rust style, to compare two strings for version-sorting:
|
||||||
|
|
||||||
@ -132,12 +131,13 @@ For the purposes of the Rust style, to compare two strings for version-sorting:
|
|||||||
these strings, treat the chunks as equal (moving on to the next chunk) but
|
these strings, treat the chunks as equal (moving on to the next chunk) but
|
||||||
remember which string had more leading zeroes.
|
remember which string had more leading zeroes.
|
||||||
- To compare two chunks if both are not numeric, compare them by Unicode
|
- To compare two chunks if both are not numeric, compare them by Unicode
|
||||||
character lexicographically, except that `_` (underscore) sorts immediately
|
character lexicographically, with two exceptions:
|
||||||
after ` ` (space) but before any other character. (This treats underscore as
|
- `_` (underscore) sorts immediately after ` ` (space) but before any other
|
||||||
a word separator, as commonly used in identifiers.)
|
character. (This treats underscore as a word separator, as commonly used in
|
||||||
- If the use of version sorting specifies further modifiers, such as sorting
|
identifiers.)
|
||||||
non-lowercase before lowercase, apply those modifiers to the lexicographic
|
- Unless otherwise specified, version-sorting should sort non-lowercase
|
||||||
sort in this step.
|
characters (characters that can start an `UpperCamelCase` identifier)
|
||||||
|
before lowercase characters.
|
||||||
- If the comparison reaches the end of the string and considers each pair of
|
- If the comparison reaches the end of the string and considers each pair of
|
||||||
chunks equal:
|
chunks equal:
|
||||||
- If one of the numeric comparisons noted the earliest point at which one
|
- If one of the numeric comparisons noted the earliest point at which one
|
||||||
@ -157,7 +157,17 @@ leading zeroes.
|
|||||||
|
|
||||||
As an example, version-sorting will sort the following strings in the order
|
As an example, version-sorting will sort the following strings in the order
|
||||||
given:
|
given:
|
||||||
- `_ZYWX`
|
- `_ZYXW`
|
||||||
|
- `_abcd`
|
||||||
|
- `A2`
|
||||||
|
- `ABCD`
|
||||||
|
- `Z_YXW`
|
||||||
|
- `ZY_XW`
|
||||||
|
- `ZY_XW`
|
||||||
|
- `ZYXW`
|
||||||
|
- `ZYXW_`
|
||||||
|
- `a1`
|
||||||
|
- `abcd`
|
||||||
- `u_zzz`
|
- `u_zzz`
|
||||||
- `u8`
|
- `u8`
|
||||||
- `u16`
|
- `u16`
|
||||||
@ -190,11 +200,7 @@ given:
|
|||||||
- `x86_64`
|
- `x86_64`
|
||||||
- `x86_128`
|
- `x86_128`
|
||||||
- `x87`
|
- `x87`
|
||||||
- `Z_YWX`
|
- `zyxw`
|
||||||
- `ZY_WX`
|
|
||||||
- `ZYW_X`
|
|
||||||
- `ZYWX`
|
|
||||||
- `ZYWX_`
|
|
||||||
|
|
||||||
### [Module-level items](items.md)
|
### [Module-level items](items.md)
|
||||||
|
|
||||||
|
@ -489,10 +489,8 @@ foo::{
|
|||||||
A *group* of imports is a set of imports on the same or sequential lines. One or
|
A *group* of imports is a set of imports on the same or sequential lines. One or
|
||||||
more blank lines or other items (e.g., a function) separate groups of imports.
|
more blank lines or other items (e.g., a function) separate groups of imports.
|
||||||
|
|
||||||
Within a group of imports, imports must be version-sorted, except that
|
Within a group of imports, imports must be version-sorted. Groups of imports
|
||||||
non-lowercase characters (characters that can start an `UpperCamelCase`
|
must not be merged or re-ordered.
|
||||||
identifier) must be sorted before lowercase characters. Groups of imports must
|
|
||||||
not be merged or re-ordered.
|
|
||||||
|
|
||||||
E.g., input:
|
E.g., input:
|
||||||
|
|
||||||
@ -520,9 +518,7 @@ re-ordering.
|
|||||||
### Ordering list import
|
### Ordering list import
|
||||||
|
|
||||||
Names in a list import must be version-sorted, except that:
|
Names in a list import must be version-sorted, except that:
|
||||||
- `self` and `super` always come first if present,
|
- `self` and `super` always come first if present, and
|
||||||
- non-lowercase characters (characters that can start an `UpperCamelCase`
|
|
||||||
identifier) must be sorted before lowercase characters, and
|
|
||||||
- groups and glob imports always come last if present.
|
- groups and glob imports always come last if present.
|
||||||
|
|
||||||
This applies recursively. For example, `a::*` comes before `b::a` but `a::b`
|
This applies recursively. For example, `a::*` comes before `b::a` but `a::b`
|
||||||
|
Loading…
Reference in New Issue
Block a user