make tidy-alphabetical use a natural sort

This commit is contained in:
Folkert de Vries
2025-05-20 20:23:47 +02:00
parent a17780db7b
commit 1dfc8406dc
19 changed files with 261 additions and 59 deletions

View File

@@ -4064,9 +4064,9 @@ mod size_asserts {
static_assert_size!(MetaItemLit, 40);
static_assert_size!(Param, 40);
static_assert_size!(Pat, 72);
static_assert_size!(PatKind, 48);
static_assert_size!(Path, 24);
static_assert_size!(PathSegment, 24);
static_assert_size!(PatKind, 48);
static_assert_size!(Stmt, 32);
static_assert_size!(StmtKind, 16);
static_assert_size!(Ty, 64);

View File

@@ -878,9 +878,9 @@ mod size_asserts {
use super::*;
// tidy-alphabetical-start
static_assert_size!(Immediate, 48);
static_assert_size!(ImmTy<'_>, 64);
static_assert_size!(Operand, 56);
static_assert_size!(Immediate, 48);
static_assert_size!(OpTy<'_>, 72);
static_assert_size!(Operand, 56);
// tidy-alphabetical-end
}

View File

@@ -1056,9 +1056,9 @@ mod size_asserts {
use super::*;
// tidy-alphabetical-start
static_assert_size!(MPlaceTy<'_>, 64);
static_assert_size!(MemPlace, 48);
static_assert_size!(MemPlaceMeta, 24);
static_assert_size!(MPlaceTy<'_>, 64);
static_assert_size!(Place, 48);
static_assert_size!(PlaceTy<'_>, 64);
// tidy-alphabetical-end

View File

@@ -4992,9 +4992,9 @@ mod size_asserts {
static_assert_size!(LetStmt<'_>, 72);
static_assert_size!(Param<'_>, 32);
static_assert_size!(Pat<'_>, 72);
static_assert_size!(PatKind<'_>, 48);
static_assert_size!(Path<'_>, 40);
static_assert_size!(PathSegment<'_>, 48);
static_assert_size!(PatKind<'_>, 48);
static_assert_size!(QPath<'_>, 24);
static_assert_size!(Res, 12);
static_assert_size!(Stmt<'_>, 32);

View File

@@ -131,8 +131,8 @@ declare_lint_pass! {
UNUSED_IMPORTS,
UNUSED_LABELS,
UNUSED_LIFETIMES,
UNUSED_MACRO_RULES,
UNUSED_MACROS,
UNUSED_MACRO_RULES,
UNUSED_MUT,
UNUSED_QUALIFICATIONS,
UNUSED_UNSAFE,

View File

@@ -774,8 +774,8 @@ bidirectional_lang_item_map! {
Future,
FutureOutput,
Iterator,
Metadata,
MetaSized,
Metadata,
Option,
PointeeSized,
PointeeTrait,

View File

@@ -230,9 +230,9 @@ TrivialLiftImpls! {
usize,
u64,
// tidy-alphabetical-start
crate::mir::Promoted,
crate::mir::interpret::AllocId,
crate::mir::interpret::Scalar,
crate::mir::Promoted,
rustc_abi::ExternAbi,
rustc_abi::Size,
rustc_hir::Safety,
@@ -267,9 +267,6 @@ TrivialTypeTraversalImpls! {
crate::mir::SwitchTargets,
crate::traits::IsConstable,
crate::traits::OverflowError,
crate::ty::abstract_const::NotConstEvaluatable,
crate::ty::adjustment::AutoBorrowMutability,
crate::ty::adjustment::PointerCoercion,
crate::ty::AdtKind,
crate::ty::AssocItem,
crate::ty::AssocKind,
@@ -281,15 +278,18 @@ TrivialTypeTraversalImpls! {
crate::ty::Placeholder<ty::BoundVar>,
crate::ty::UserTypeAnnotationIndex,
crate::ty::ValTree<'tcx>,
crate::ty::abstract_const::NotConstEvaluatable,
crate::ty::adjustment::AutoBorrowMutability,
crate::ty::adjustment::PointerCoercion,
rustc_abi::FieldIdx,
rustc_abi::VariantIdx,
rustc_ast::InlineAsmOptions,
rustc_ast::InlineAsmTemplatePiece,
rustc_hir::CoroutineKind,
rustc_hir::def_id::LocalDefId,
rustc_hir::HirId,
rustc_hir::MatchSource,
rustc_hir::RangeEnd,
rustc_hir::def_id::LocalDefId,
rustc_span::Ident,
rustc_span::Span,
rustc_span::Symbol,
@@ -303,9 +303,9 @@ TrivialTypeTraversalImpls! {
// interners).
TrivialTypeTraversalAndLiftImpls! {
// tidy-alphabetical-start
crate::ty::instance::ReifyReason,
crate::ty::ParamConst,
crate::ty::ParamTy,
crate::ty::instance::ReifyReason,
rustc_hir::def_id::DefId,
// tidy-alphabetical-end
}

View File

@@ -212,9 +212,6 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("flagm2", Unstable(sym::aarch64_unstable_target_feature), &[]),
// We forbid directly toggling just `fp-armv8`; it must be toggled with `neon`.
("fp-armv8", Stability::Forbidden { reason: "Rust ties `fp-armv8` to `neon`" }, &[]),
// FEAT_FP16
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
("fp16", Stable, &["neon"]),
// FEAT_FP8
("fp8", Unstable(sym::aarch64_unstable_target_feature), &["faminmax", "lut", "bf16"]),
// FEAT_FP8DOT2
@@ -223,6 +220,9 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("fp8dot4", Unstable(sym::aarch64_unstable_target_feature), &["fp8fma"]),
// FEAT_FP8FMA
("fp8fma", Unstable(sym::aarch64_unstable_target_feature), &["fp8"]),
// FEAT_FP16
// Rust ties FP and Neon: https://github.com/rust-lang/rust/pull/91608
("fp16", Stable, &["neon"]),
// FEAT_FRINTTS
("frintts", Stable, &[]),
// FEAT_HBC
@@ -236,10 +236,10 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("lor", Stable, &[]),
// FEAT_LSE
("lse", Stable, &[]),
// FEAT_LSE128
("lse128", Unstable(sym::aarch64_unstable_target_feature), &["lse"]),
// FEAT_LSE2
("lse2", Unstable(sym::aarch64_unstable_target_feature), &[]),
// FEAT_LSE128
("lse128", Unstable(sym::aarch64_unstable_target_feature), &["lse"]),
// FEAT_LUT
("lut", Unstable(sym::aarch64_unstable_target_feature), &[]),
// FEAT_MOPS
@@ -283,14 +283,14 @@ static AARCH64_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("sme", Unstable(sym::aarch64_unstable_target_feature), &["bf16"]),
// FEAT_SME_B16B16
("sme-b16b16", Unstable(sym::aarch64_unstable_target_feature), &["bf16", "sme2", "sve-b16b16"]),
// FEAT_SME_F16F16
("sme-f16f16", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
// FEAT_SME_F64F64
("sme-f64f64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
// FEAT_SME_F8F16
("sme-f8f16", Unstable(sym::aarch64_unstable_target_feature), &["sme-f8f32"]),
// FEAT_SME_F8F32
("sme-f8f32", Unstable(sym::aarch64_unstable_target_feature), &["sme2", "fp8"]),
// FEAT_SME_F16F16
("sme-f16f16", Unstable(sym::aarch64_unstable_target_feature), &["sme2"]),
// FEAT_SME_F64F64
("sme-f64f64", Unstable(sym::aarch64_unstable_target_feature), &["sme"]),
// FEAT_SME_FA64
("sme-fa64", Unstable(sym::aarch64_unstable_target_feature), &["sme", "sve2"]),
// FEAT_SME_I16I64
@@ -376,8 +376,8 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("amx-avx512", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-bf16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-complex", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-fp16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-fp8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-fp16", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-int8", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-movrs", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("amx-tf32", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
@@ -385,6 +385,7 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("amx-transpose", Unstable(sym::x86_amx_intrinsics), &["amx-tile"]),
("apxf", Unstable(sym::apx_target_feature), &[]),
("avx", Stable, &["sse4.2"]),
("avx2", Stable, &["avx"]),
(
"avx10.1",
Unstable(sym::avx10_target_feature),
@@ -405,7 +406,6 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
],
),
("avx10.2", Unstable(sym::avx10_target_feature), &["avx10.1"]),
("avx2", Stable, &["avx"]),
("avx512bf16", Stable, &["avx512bw"]),
("avx512bitalg", Stable, &["avx512bw"]),
("avx512bw", Stable, &["avx512f"]),
@@ -423,8 +423,8 @@ static X86_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("avxifma", Stable, &["avx2"]),
("avxneconvert", Stable, &["avx2"]),
("avxvnni", Stable, &["avx2"]),
("avxvnniint16", Stable, &["avx2"]),
("avxvnniint8", Stable, &["avx2"]),
("avxvnniint16", Stable, &["avx2"]),
("bmi1", Stable, &[]),
("bmi2", Stable, &[]),
("cmpxchg16b", Stable, &[]),
@@ -498,12 +498,12 @@ static POWERPC_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("altivec", Unstable(sym::powerpc_target_feature), &[]),
("msync", Unstable(sym::powerpc_target_feature), &[]),
("partword-atomics", Unstable(sym::powerpc_target_feature), &[]),
("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
("power8-altivec", Unstable(sym::powerpc_target_feature), &["altivec"]),
("power8-crypto", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
("power8-vector", Unstable(sym::powerpc_target_feature), &["vsx", "power8-altivec"]),
("power9-altivec", Unstable(sym::powerpc_target_feature), &["power8-altivec"]),
("power9-vector", Unstable(sym::powerpc_target_feature), &["power8-vector", "power9-altivec"]),
("power10-vector", Unstable(sym::powerpc_target_feature), &["power9-vector"]),
("quadword-atomics", Unstable(sym::powerpc_target_feature), &[]),
("vsx", Unstable(sym::powerpc_target_feature), &["altivec"]),
// tidy-alphabetical-end
@@ -535,8 +535,8 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("unaligned-scalar-mem", Unstable(sym::riscv_target_feature), &[]),
("unaligned-vector-mem", Unstable(sym::riscv_target_feature), &[]),
("v", Unstable(sym::riscv_target_feature), &["zvl128b", "zve64d"]),
("za128rs", Unstable(sym::riscv_target_feature), &[]),
("za64rs", Unstable(sym::riscv_target_feature), &["za128rs"]), // Za64rs ⊃ Za128rs
("za128rs", Unstable(sym::riscv_target_feature), &[]),
("zaamo", Unstable(sym::riscv_target_feature), &[]),
("zabha", Unstable(sym::riscv_target_feature), &["zaamo"]),
("zacas", Unstable(sym::riscv_target_feature), &["zaamo"]),
@@ -613,18 +613,18 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("zvksg", Unstable(sym::riscv_target_feature), &["zvks", "zvkg"]),
("zvksh", Unstable(sym::riscv_target_feature), &["zve32x"]),
("zvkt", Unstable(sym::riscv_target_feature), &[]),
("zvl1024b", Unstable(sym::riscv_target_feature), &["zvl512b"]),
("zvl128b", Unstable(sym::riscv_target_feature), &["zvl64b"]),
("zvl16384b", Unstable(sym::riscv_target_feature), &["zvl8192b"]),
("zvl2048b", Unstable(sym::riscv_target_feature), &["zvl1024b"]),
("zvl256b", Unstable(sym::riscv_target_feature), &["zvl128b"]),
("zvl32768b", Unstable(sym::riscv_target_feature), &["zvl16384b"]),
("zvl32b", Unstable(sym::riscv_target_feature), &[]),
("zvl4096b", Unstable(sym::riscv_target_feature), &["zvl2048b"]),
("zvl512b", Unstable(sym::riscv_target_feature), &["zvl256b"]),
("zvl64b", Unstable(sym::riscv_target_feature), &["zvl32b"]),
("zvl65536b", Unstable(sym::riscv_target_feature), &["zvl32768b"]),
("zvl128b", Unstable(sym::riscv_target_feature), &["zvl64b"]),
("zvl256b", Unstable(sym::riscv_target_feature), &["zvl128b"]),
("zvl512b", Unstable(sym::riscv_target_feature), &["zvl256b"]),
("zvl1024b", Unstable(sym::riscv_target_feature), &["zvl512b"]),
("zvl2048b", Unstable(sym::riscv_target_feature), &["zvl1024b"]),
("zvl4096b", Unstable(sym::riscv_target_feature), &["zvl2048b"]),
("zvl8192b", Unstable(sym::riscv_target_feature), &["zvl4096b"]),
("zvl16384b", Unstable(sym::riscv_target_feature), &["zvl8192b"]),
("zvl32768b", Unstable(sym::riscv_target_feature), &["zvl16384b"]),
("zvl65536b", Unstable(sym::riscv_target_feature), &["zvl32768b"]),
// tidy-alphabetical-end
];
@@ -651,13 +651,13 @@ const BPF_FEATURES: &[(&str, Stability, ImpliedFeatures)] =
static CSKY_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
// tidy-alphabetical-start
("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
("2e3", Unstable(sym::csky_target_feature), &["e2"]),
("3e3r1", Unstable(sym::csky_target_feature), &[]),
("3e3r2", Unstable(sym::csky_target_feature), &["3e3r1", "doloop"]),
("3e3r3", Unstable(sym::csky_target_feature), &["doloop"]),
("3e7", Unstable(sym::csky_target_feature), &["2e3"]),
("7e10", Unstable(sym::csky_target_feature), &["3e7"]),
("10e60", Unstable(sym::csky_target_feature), &["7e10"]),
("cache", Unstable(sym::csky_target_feature), &[]),
("doloop", Unstable(sym::csky_target_feature), &[]),
("dsp1e2", Unstable(sym::csky_target_feature), &[]),
@@ -726,12 +726,12 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
("guarded-storage", Unstable(sym::s390x_target_feature), &[]),
("high-word", Unstable(sym::s390x_target_feature), &[]),
// LLVM does not define message-security-assist-extension versions 1, 2, 6, 10 and 11.
("message-security-assist-extension12", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension3", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension4", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension5", Unstable(sym::s390x_target_feature), &[]),
("message-security-assist-extension8", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3"]),
("message-security-assist-extension9", Unstable(sym::s390x_target_feature), &["message-security-assist-extension3", "message-security-assist-extension4"]),
("message-security-assist-extension12", Unstable(sym::s390x_target_feature), &[]),
("miscellaneous-extensions-2", Unstable(sym::s390x_target_feature), &[]),
("miscellaneous-extensions-3", Unstable(sym::s390x_target_feature), &[]),
("miscellaneous-extensions-4", Unstable(sym::s390x_target_feature), &[]),

View File

@@ -29,8 +29,8 @@ pub enum TraitSolverLangItem {
Future,
FutureOutput,
Iterator,
Metadata,
MetaSized,
Metadata,
Option,
PointeeSized,
PointeeTrait,

View File

@@ -53,11 +53,11 @@ TrivialTypeTraversalImpls! {
crate::BoundConstness,
crate::DebruijnIndex,
crate::PredicatePolarity,
crate::UniverseIndex,
crate::Variance,
crate::solve::BuiltinImplSource,
crate::solve::Certainty,
crate::solve::GoalSource,
crate::UniverseIndex,
crate::Variance,
rustc_ast_ir::Mutability,
// tidy-alphabetical-end
}

View File

@@ -150,8 +150,8 @@
#![feature(doc_cfg_hide)]
#![feature(doc_notable_trait)]
#![feature(extern_types)]
#![feature(f128)]
#![feature(f16)]
#![feature(f128)]
#![feature(freeze_impls)]
#![feature(fundamental)]
#![feature(if_let_guard)]

View File

@@ -34,8 +34,8 @@
#![feature(exact_size_is_empty)]
#![feature(extend_one)]
#![feature(extern_types)]
#![feature(f128)]
#![feature(f16)]
#![feature(f128)]
#![feature(float_algebraic)]
#![feature(float_gamma)]
#![feature(float_minimum_maximum)]

View File

@@ -462,8 +462,8 @@ impl ErrorKind {
Deadlock => "deadlock",
DirectoryNotEmpty => "directory not empty",
ExecutableFileBusy => "executable file busy",
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
FileTooLarge => "file too large",
FilesystemLoop => "filesystem loop or indirection limit (e.g. symlink loop)",
HostUnreachable => "host unreachable",
InProgress => "in progress",
Interrupted => "operation interrupted",

View File

@@ -290,8 +290,8 @@
#![feature(doc_notable_trait)]
#![feature(dropck_eyepatch)]
#![feature(extended_varargs_abi_support)]
#![feature(f128)]
#![feature(f16)]
#![feature(f128)]
#![feature(ffi_const)]
#![feature(formatting_options)]
#![feature(if_let_guard)]

View File

@@ -271,20 +271,20 @@ impl WinError {
// tidy-alphabetical-start
pub const ACCESS_DENIED: Self = Self::new(c::ERROR_ACCESS_DENIED);
pub const ALREADY_EXISTS: Self = Self::new(c::ERROR_ALREADY_EXISTS);
pub const BAD_NET_NAME: Self = Self::new(c::ERROR_BAD_NET_NAME);
pub const BAD_NETPATH: Self = Self::new(c::ERROR_BAD_NETPATH);
pub const BAD_NET_NAME: Self = Self::new(c::ERROR_BAD_NET_NAME);
pub const CANT_ACCESS_FILE: Self = Self::new(c::ERROR_CANT_ACCESS_FILE);
pub const DELETE_PENDING: Self = Self::new(c::ERROR_DELETE_PENDING);
pub const DIR_NOT_EMPTY: Self = Self::new(c::ERROR_DIR_NOT_EMPTY);
pub const DIRECTORY: Self = Self::new(c::ERROR_DIRECTORY);
pub const DIR_NOT_EMPTY: Self = Self::new(c::ERROR_DIR_NOT_EMPTY);
pub const FILE_NOT_FOUND: Self = Self::new(c::ERROR_FILE_NOT_FOUND);
pub const INSUFFICIENT_BUFFER: Self = Self::new(c::ERROR_INSUFFICIENT_BUFFER);
pub const INVALID_FUNCTION: Self = Self::new(c::ERROR_INVALID_FUNCTION);
pub const INVALID_HANDLE: Self = Self::new(c::ERROR_INVALID_HANDLE);
pub const INVALID_PARAMETER: Self = Self::new(c::ERROR_INVALID_PARAMETER);
pub const NO_MORE_FILES: Self = Self::new(c::ERROR_NO_MORE_FILES);
pub const NOT_FOUND: Self = Self::new(c::ERROR_NOT_FOUND);
pub const NOT_SUPPORTED: Self = Self::new(c::ERROR_NOT_SUPPORTED);
pub const NO_MORE_FILES: Self = Self::new(c::ERROR_NO_MORE_FILES);
pub const OPERATION_ABORTED: Self = Self::new(c::ERROR_OPERATION_ABORTED);
pub const PATH_NOT_FOUND: Self = Self::new(c::ERROR_PATH_NOT_FOUND);
pub const SHARING_VIOLATION: Self = Self::new(c::ERROR_SHARING_VIOLATION);

View File

@@ -57,18 +57,18 @@ fn aarch64_linux() {
println!("fhm: {}", is_aarch64_feature_detected!("fhm"));
println!("flagm2: {}", is_aarch64_feature_detected!("flagm2"));
println!("flagm: {}", is_aarch64_feature_detected!("flagm"));
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
println!("fp8: {}", is_aarch64_feature_detected!("fp8"));
println!("fp8dot2: {}", is_aarch64_feature_detected!("fp8dot2"));
println!("fp8dot4: {}", is_aarch64_feature_detected!("fp8dot4"));
println!("fp8fma: {}", is_aarch64_feature_detected!("fp8fma"));
println!("fp16: {}", is_aarch64_feature_detected!("fp16"));
println!("fpmr: {}", is_aarch64_feature_detected!("fpmr"));
println!("frintts: {}", is_aarch64_feature_detected!("frintts"));
println!("hbc: {}", is_aarch64_feature_detected!("hbc"));
println!("i8mm: {}", is_aarch64_feature_detected!("i8mm"));
println!("jsconv: {}", is_aarch64_feature_detected!("jsconv"));
println!("lse128: {}", is_aarch64_feature_detected!("lse128"));
println!("lse2: {}", is_aarch64_feature_detected!("lse2"));
println!("lse128: {}", is_aarch64_feature_detected!("lse128"));
println!("lse: {}", is_aarch64_feature_detected!("lse"));
println!("lut: {}", is_aarch64_feature_detected!("lut"));
println!("mops: {}", is_aarch64_feature_detected!("mops"));
@@ -87,10 +87,10 @@ fn aarch64_linux() {
println!("sha3: {}", is_aarch64_feature_detected!("sha3"));
println!("sm4: {}", is_aarch64_feature_detected!("sm4"));
println!("sme-b16b16: {}", is_aarch64_feature_detected!("sme-b16b16"));
println!("sme-f16f16: {}", is_aarch64_feature_detected!("sme-f16f16"));
println!("sme-f64f64: {}", is_aarch64_feature_detected!("sme-f64f64"));
println!("sme-f8f16: {}", is_aarch64_feature_detected!("sme-f8f16"));
println!("sme-f8f32: {}", is_aarch64_feature_detected!("sme-f8f32"));
println!("sme-f16f16: {}", is_aarch64_feature_detected!("sme-f16f16"));
println!("sme-f64f64: {}", is_aarch64_feature_detected!("sme-f64f64"));
println!("sme-fa64: {}", is_aarch64_feature_detected!("sme-fa64"));
println!("sme-i16i64: {}", is_aarch64_feature_detected!("sme-i16i64"));
println!("sme-lutv2: {}", is_aarch64_feature_detected!("sme-lutv2"));

View File

@@ -1036,18 +1036,18 @@ impl Step for PlainSourceTarball {
let src_files = [
// tidy-alphabetical-start
".gitmodules",
"bootstrap.example.toml",
"Cargo.lock",
"Cargo.toml",
"configure",
"CONTRIBUTING.md",
"COPYRIGHT",
"Cargo.lock",
"Cargo.toml",
"LICENSE-APACHE",
"license-metadata.json",
"LICENSE-MIT",
"README.md",
"RELEASES.md",
"REUSE.toml",
"bootstrap.example.toml",
"configure",
"license-metadata.json",
"x",
"x.ps1",
"x.py",

View File

@@ -19,7 +19,9 @@
//! If a line ends with an opening delimiter, we effectively join the following line to it before
//! checking it. E.g. `foo(\nbar)` is treated like `foo(bar)`.
use std::cmp::Ordering;
use std::fmt::Display;
use std::iter::Peekable;
use std::path::Path;
use crate::walk::{filter_dirs, walk};
@@ -99,9 +101,9 @@ fn check_section<'a>(
continue;
}
let prev_line_trimmed_lowercase = prev_line.trim_start_matches(' ').to_lowercase();
let prev_line_trimmed_lowercase = prev_line.trim_start_matches(' ');
if trimmed_line.to_lowercase() < prev_line_trimmed_lowercase {
if version_sort(&trimmed_line, &prev_line_trimmed_lowercase).is_lt() {
tidy_error_ext!(err, bad, "{file}:{}: line not in alphabetical order", idx + 1);
}
@@ -143,3 +145,56 @@ pub fn check(path: &Path, bad: &mut bool) {
check_lines(file, lines, &mut crate::tidy_error, bad)
});
}
fn consume_numeric_prefix<I: Iterator<Item = char>>(it: &mut Peekable<I>) -> String {
let mut result = String::new();
while let Some(&c) = it.peek() {
if !c.is_numeric() {
break;
}
result.push(c);
it.next();
}
result
}
// A sorting function that is case-sensitive, and sorts sequences of digits by their numeric value,
// so that `9` sorts before `12`.
fn version_sort(a: &str, b: &str) -> Ordering {
let mut it1 = a.chars().peekable();
let mut it2 = b.chars().peekable();
while let (Some(x), Some(y)) = (it1.peek(), it2.peek()) {
match (x.is_numeric(), y.is_numeric()) {
(true, true) => {
let num1: String = consume_numeric_prefix(it1.by_ref());
let num2: String = consume_numeric_prefix(it2.by_ref());
let int1: u64 = num1.parse().unwrap();
let int2: u64 = num2.parse().unwrap();
// Compare strings when the numeric value is equal to handle "00" versus "0".
match int1.cmp(&int2).then_with(|| num1.cmp(&num2)) {
Ordering::Equal => continue,
different => return different,
}
}
(false, false) => match x.cmp(y) {
Ordering::Equal => {
it1.next();
it2.next();
continue;
}
different => return different,
},
(false, true) | (true, false) => {
return x.cmp(y);
}
}
}
it1.next().cmp(&it2.next())
}

View File

@@ -3,6 +3,7 @@ use std::str::from_utf8;
use super::*;
#[track_caller]
fn test(lines: &str, name: &str, expected_msg: &str, expected_bad: bool) {
let mut actual_msg = Vec::new();
let mut actual_bad = false;
@@ -15,10 +16,12 @@ fn test(lines: &str, name: &str, expected_msg: &str, expected_bad: bool) {
assert_eq!(expected_bad, actual_bad);
}
#[track_caller]
fn good(lines: &str) {
test(lines, "good", "", false);
}
#[track_caller]
fn bad(lines: &str, expected_msg: &str) {
test(lines, "bad", expected_msg, true);
}
@@ -187,3 +190,147 @@ fn test_double_end() {
";
bad(lines, "bad:5 found `tidy-alphabetical-end` expecting `tidy-alphabetical-start`");
}
#[test]
fn test_numeric_good() {
good(
"\
# tidy-alphabetical-start
rustc_ast = { path = \"../rustc_ast\" }
rustc_ast_lowering = { path = \"../rustc_ast_lowering\" }
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
fp-armv8
fp16
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
item1
item2
item10
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
foo
foo_
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
foo-bar
foo_bar
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
sme-lutv2
sme2
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
v5te
v6
v6k
v6t2
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
zve64d
zve64f
# tidy-alphabetical-end
",
);
// Case is significant.
good(
"\
# tidy-alphabetical-start
_ZYXW
_abcd
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
v0
v00
v000
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
w005s09t
w5s009t
# tidy-alphabetical-end
",
);
good(
"\
# tidy-alphabetical-start
v0s
v00t
# tidy-alphabetical-end
",
);
}
#[test]
fn test_numeric_bad() {
let lines = "\
# tidy-alphabetical-start
item1
item10
item2
# tidy-alphabetical-end
";
bad(lines, "bad:4: line not in alphabetical order");
let lines = "\
# tidy-alphabetical-start
zve64f
zve64d
# tidy-alphabetical-end
";
bad(lines, "bad:3: line not in alphabetical order");
let lines = "\
# tidy-alphabetical-start
000
00
# tidy-alphabetical-end
";
bad(lines, "bad:3: line not in alphabetical order");
}