rust/compiler
Matthias Krüger 158340f561
Rollup merge of #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?)
2025-06-26 15:47:17 +02:00
..
rustc Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_abi compiler: Trim the misleading C from ExternAbi::CCmse* 2025-06-25 00:52:09 -07:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering compiler: remove misleading 'c' from abi_c_cmse_nonsecure_call feature 2025-06-25 00:52:10 -07:00
rustc_ast_passes Error on invalid signatures for interrupt ABIs 2025-06-24 14:40:11 +02:00
rustc_ast_pretty Rollup merge of #135731 - frank-king:feature/pin-borrow, r=eholk,traviscross 2025-06-24 19:45:29 -07:00
rustc_attr_data_structures encode_cross_crate for hir attributes 2025-06-25 22:10:40 +02:00
rustc_attr_parsing Rollup merge of #142825 - jdonszelmann:track-caller, r=oli-obk 2025-06-24 19:45:32 -07:00
rustc_baked_icu_data Add unreachable_pub to RUSTC_LINT_FLAGS for compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_borrowck Rollup merge of #124595 - estebank:issue-104232, r=davidtwco 2025-06-26 15:47:16 +02:00
rustc_builtin_macros Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_codegen_cranelift Rollup merge of #142955 - bjorn3:cg_clif_test_fixes, r=jieyouxu 2025-06-24 19:45:34 -07:00
rustc_codegen_gcc Remove dead instructions in terminate blocks 2025-06-22 11:38:47 -04:00
rustc_codegen_llvm Auto merge of #143026 - jdonszelmann:rollup-z7mkuyt, r=jdonszelmann 2025-06-25 23:33:23 +00:00
rustc_codegen_ssa Auto merge of #142879 - Mark-Simulacrum:opt-cleanup, r=WaffleLapkin 2025-06-25 17:33:39 +00:00
rustc_const_eval Rollup merge of #141311 - folkertdev:tidy-natural-sort, r=jieyouxu 2025-06-26 15:47:17 +02:00
rustc_data_structures Rollup merge of #142868 - klensy:dc, r=oli-obk 2025-06-22 17:35:36 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl rustc_session: Add a structure for keeping both explicit and default sysroots 2025-06-24 16:00:04 +03:00
rustc_error_codes compiler: Trim the misleading C of C-cmse from errors 2025-06-25 00:52:10 -07:00
rustc_error_messages rustc_session: Add a structure for keeping both explicit and default sysroots 2025-06-24 16:00:04 +03:00
rustc_errors Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_expand Rollup merge of #142934 - nnethercote:tweak-macro-stats, r=petrochenkov 2025-06-24 19:45:33 -07:00
rustc_feature Auto merge of #143026 - jdonszelmann:rollup-z7mkuyt, r=jdonszelmann 2025-06-25 23:33:23 +00:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
rustc_hir_analysis Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_hir_pretty Rollup merge of #135731 - frank-king:feature/pin-borrow, r=eholk,traviscross 2025-06-24 19:45:29 -07:00
rustc_hir_typeck Simplify IfCause 2025-06-26 03:43:01 +00:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index index: add method for checking range on DenseBitSet 2025-06-04 00:47:12 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer Simplify IfCause 2025-06-26 03:43:01 +00:00
rustc_interface Rollup merge of #142934 - nnethercote:tweak-macro-stats, r=petrochenkov 2025-06-24 19:45:33 -07:00
rustc_lexer rustc_lexer: typo fix + small cleanups 2025-06-06 13:08:16 +00:00
rustc_lint Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_lint_defs make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
rustc_llvm rustc_llvm: add Windows system libs only when cross-compiling from Windows 2025-05-31 15:47:14 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg 2025-06-25 21:07:16 +08:00
rustc_metadata Auto merge of #143026 - jdonszelmann:rollup-z7mkuyt, r=jdonszelmann 2025-06-25 23:33:23 +00:00
rustc_middle Rollup merge of #141311 - folkertdev:tidy-natural-sort, r=jieyouxu 2025-06-26 15:47:17 +02:00
rustc_mir_build Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_mir_dataflow update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
rustc_mir_transform Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_monomorphize Skip collecting no-op DropGlue in vtables 2025-06-21 18:59:36 -04:00
rustc_next_trait_solver Auto merge of #142746 - compiler-errors:super-implied-outlives, r=lcnr 2025-06-25 10:10:21 +00:00
rustc_parse Auto merge of #142997 - workingjubilee:rollup-6lxec87, r=workingjubilee 2025-06-25 04:05:47 +00:00
rustc_parse_format update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_passes Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_pattern_analysis Add #[loop_match] for improved DFA codegen 2025-06-23 20:43:04 +02:00
rustc_privacy Reorder fields in hir::ItemKind variants. 2025-05-30 02:23:20 +10:00
rustc_proc_macro update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
rustc_query_impl Auto merge of #140145 - Zoxc:job-server-proxy, r=SparrowLii 2025-05-01 04:11:52 +00:00
rustc_query_system Rollup merge of #142384 - celinval:chores-rayon-mv, r=oli-obk 2025-06-20 23:25:54 -04:00
rustc_resolve Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk 2025-06-25 22:14:55 +02:00
rustc_sanitizers Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
rustc_serialize Add a few inline directives in rustc_serialize. 2025-06-21 23:54:16 +00:00
rustc_session Rollup merge of #142809 - KMJ-007:ad-type-analysis-flag, r=ZuseZ4 2025-06-25 22:14:55 +02:00
rustc_smir compiler: Trim the misleading C from ExternAbi::CCmse* 2025-06-25 00:52:09 -07:00
rustc_span compiler: remove misleading 'c' from abi_c_cmse_nonsecure_call feature 2025-06-25 00:52:10 -07:00
rustc_symbol_mangling Change __rust_no_alloc_shim_is_unstable to be a function 2025-06-16 10:54:07 -07:00
rustc_target Rollup merge of #141311 - folkertdev:tidy-natural-sort, r=jieyouxu 2025-06-26 15:47:17 +02:00
rustc_thread_pool Apply suggestions from code review 2025-06-16 12:27:47 -07:00
rustc_trait_selection Simplify IfCause 2025-06-26 03:43:01 +00:00
rustc_traits FIXME(-Znext-solver) triage 2025-06-03 14:23:56 +02:00
rustc_transmute transmutability: shift abstraction boundary 2025-06-09 14:08:12 +00:00
rustc_ty_utils Add #[loop_match] for improved DFA codegen 2025-06-23 20:43:04 +02:00
rustc_type_ir Rollup merge of #141311 - folkertdev:tidy-natural-sort, r=jieyouxu 2025-06-26 15:47:17 +02:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir Change rustc_driver dependency on stable_mir crate 2025-04-30 15:39:52 -07:00