Skip to content

Commit d0835ef

Browse files
authored
Rollup merge of rust-lang#141311 - folkertdev:tidy-natural-sort, r=jieyouxu
make `tidy-alphabetical` use a natural sort The idea here is that these lines should be correctly sorted, even though a naive string comparison would say they are not: ``` foo2 foo10 ``` This is the ["natural sort order"](https://en.wikipedia.org/wiki/Natural_sort_order). There is more discussion in [#t-compiler/help > tidy natural sort](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/tidy.20natural.20sort/with/519111079) Unfortunately, no standard sorting tools are smart enough to to this automatically (casting some doubt on whether we should make this change). Here are some sort outputs: ``` > cat foo.txt | sort foo foo1 foo10 foo2 mp mp1e2 np", np1e2", > cat foo.txt | sort -n foo foo1 foo10 foo2 mp mp1e2 np", np1e2", > cat foo.txt | sort -V foo foo1 foo2 foo10 mp mp1e2 np1e2", np", ``` Disappointingly, "numeric" sort does not actually have the behavior we want. It only sorts by numeric value if the line starts with a number. The "version" sort looks promising, but does something very unintuitive if you look at the final 4 values. None of the other options seem to have the desired behavior in all cases: ``` -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order consider only blanks and alphanumeric characters -f, --ignore-case fold lower case to upper case characters -g, --general-numeric-sort compare according to general numerical value -i, --ignore-nonprinting consider only printable characters -M, --month-sort compare (unknown) < 'JAN' < ... < 'DEC' -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G) -n, --numeric-sort compare according to string numerical value -R, --random-sort shuffle, but group identical keys. See shuf(1) --random-source=FILE get random bytes from FILE -r, --reverse reverse the result of comparisons --sort=WORD sort according to WORD: general-numeric -g, human-numeric -h, month -M, numeric -n, random -R, version -V -V, --version-sort natural sort of (version) numbers within text ``` r? ```@Noratrieb``` (it sounded like you know this code?)
2 parents 86d7052 + 0b75ada commit d0835ef

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@
150150
#![feature(doc_cfg_hide)]
151151
#![feature(doc_notable_trait)]
152152
#![feature(extern_types)]
153-
#![feature(f128)]
154153
#![feature(f16)]
154+
#![feature(f128)]
155155
#![feature(freeze_impls)]
156156
#![feature(fundamental)]
157157
#![feature(if_let_guard)]

coretests/tests/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#![feature(exact_size_is_empty)]
3535
#![feature(extend_one)]
3636
#![feature(extern_types)]
37-
#![feature(f128)]
3837
#![feature(f16)]
38+
#![feature(f128)]
3939
#![feature(float_algebraic)]
4040
#![feature(float_gamma)]
4141
#![feature(float_minimum_maximum)]

std/src/io/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ impl ErrorKind {
462462
Deadlock => "deadlock",
463463
DirectoryNotEmpty => "directory not empty",
464464
ExecutableFileBusy => "executable file busy",
465-
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
466465
FileTooLarge => "file too large",
466+
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
467467
HostUnreachable => "host unreachable",
468468
InProgress => "in progress",
469469
Interrupted => "operation interrupted",

std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@
290290
#![feature(doc_notable_trait)]
291291
#![feature(dropck_eyepatch)]
292292
#![feature(extended_varargs_abi_support)]
293-
#![feature(f128)]
294293
#![feature(f16)]
294+
#![feature(f128)]
295295
#![feature(ffi_const)]
296296
#![feature(formatting_options)]
297297
#![feature(if_let_guard)]

std/src/sys/pal/windows/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,20 +271,20 @@ impl WinError {
271271
// tidy-alphabetical-start
272272
pub const ACCESS_DENIED: Self = Self::new(c::ERROR_ACCESS_DENIED);
273273
pub const ALREADY_EXISTS: Self = Self::new(c::ERROR_ALREADY_EXISTS);
274-
pub const BAD_NET_NAME: Self = Self::new(c::ERROR_BAD_NET_NAME);
275274
pub const BAD_NETPATH: Self = Self::new(c::ERROR_BAD_NETPATH);
275+
pub const BAD_NET_NAME: Self = Self::new(c::ERROR_BAD_NET_NAME);
276276
pub const CANT_ACCESS_FILE: Self = Self::new(c::ERROR_CANT_ACCESS_FILE);
277277
pub const DELETE_PENDING: Self = Self::new(c::ERROR_DELETE_PENDING);
278-
pub const DIR_NOT_EMPTY: Self = Self::new(c::ERROR_DIR_NOT_EMPTY);
279278
pub const DIRECTORY: Self = Self::new(c::ERROR_DIRECTORY);
279+
pub const DIR_NOT_EMPTY: Self = Self::new(c::ERROR_DIR_NOT_EMPTY);
280280
pub const FILE_NOT_FOUND: Self = Self::new(c::ERROR_FILE_NOT_FOUND);
281281
pub const INSUFFICIENT_BUFFER: Self = Self::new(c::ERROR_INSUFFICIENT_BUFFER);
282282
pub const INVALID_FUNCTION: Self = Self::new(c::ERROR_INVALID_FUNCTION);
283283
pub const INVALID_HANDLE: Self = Self::new(c::ERROR_INVALID_HANDLE);
284284
pub const INVALID_PARAMETER: Self = Self::new(c::ERROR_INVALID_PARAMETER);
285-
pub const NO_MORE_FILES: Self = Self::new(c::ERROR_NO_MORE_FILES);
286285
pub const NOT_FOUND: Self = Self::new(c::ERROR_NOT_FOUND);
287286
pub const NOT_SUPPORTED: Self = Self::new(c::ERROR_NOT_SUPPORTED);
287+
pub const NO_MORE_FILES: Self = Self::new(c::ERROR_NO_MORE_FILES);
288288
pub const OPERATION_ABORTED: Self = Self::new(c::ERROR_OPERATION_ABORTED);
289289
pub const PATH_NOT_FOUND: Self = Self::new(c::ERROR_PATH_NOT_FOUND);
290290
pub const SHARING_VIOLATION: Self = Self::new(c::ERROR_SHARING_VIOLATION);

std/tests/run-time-detect.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ fn aarch64_linux() {
5757
println!("fhm: {}", is_aarch64_feature_detected!("fhm"));
5858
println!("flagm2: {}", is_aarch64_feature_detected!("flagm2"));
5959
println!("flagm: {}", is_aarch64_feature_detected!("flagm"));
60-
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
6160
println!("fp8: {}", is_aarch64_feature_detected!("fp8"));
6261
println!("fp8dot2: {}", is_aarch64_feature_detected!("fp8dot2"));
6362
println!("fp8dot4: {}", is_aarch64_feature_detected!("fp8dot4"));
6463
println!("fp8fma: {}", is_aarch64_feature_detected!("fp8fma"));
64+
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
6565
println!("fpmr: {}", is_aarch64_feature_detected!("fpmr"));
6666
println!("frintts: {}", is_aarch64_feature_detected!("frintts"));
6767
println!("hbc: {}", is_aarch64_feature_detected!("hbc"));
6868
println!("i8mm: {}", is_aarch64_feature_detected!("i8mm"));
6969
println!("jsconv: {}", is_aarch64_feature_detected!("jsconv"));
70-
println!("lse128: {}", is_aarch64_feature_detected!("lse128"));
7170
println!("lse2: {}", is_aarch64_feature_detected!("lse2"));
71+
println!("lse128: {}", is_aarch64_feature_detected!("lse128"));
7272
println!("lse: {}", is_aarch64_feature_detected!("lse"));
7373
println!("lut: {}", is_aarch64_feature_detected!("lut"));
7474
println!("mops: {}", is_aarch64_feature_detected!("mops"));
@@ -87,10 +87,10 @@ fn aarch64_linux() {
8787
println!("sha3: {}", is_aarch64_feature_detected!("sha3"));
8888
println!("sm4: {}", is_aarch64_feature_detected!("sm4"));
8989
println!("sme-b16b16: {}", is_aarch64_feature_detected!("sme-b16b16"));
90-
println!("sme-f16f16: {}", is_aarch64_feature_detected!("sme-f16f16"));
91-
println!("sme-f64f64: {}", is_aarch64_feature_detected!("sme-f64f64"));
9290
println!("sme-f8f16: {}", is_aarch64_feature_detected!("sme-f8f16"));
9391
println!("sme-f8f32: {}", is_aarch64_feature_detected!("sme-f8f32"));
92+
println!("sme-f16f16: {}", is_aarch64_feature_detected!("sme-f16f16"));
93+
println!("sme-f64f64: {}", is_aarch64_feature_detected!("sme-f64f64"));
9494
println!("sme-fa64: {}", is_aarch64_feature_detected!("sme-fa64"));
9595
println!("sme-i16i64: {}", is_aarch64_feature_detected!("sme-i16i64"));
9696
println!("sme-lutv2: {}", is_aarch64_feature_detected!("sme-lutv2"));

0 commit comments

Comments
 (0)