diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2025-02-10 03:57:32 -0800 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2025-02-11 20:18:01 -0800 |
| commit | 8abff35b41b8de89da35ab851f931d6a582f7670 (patch) | |
| tree | 9fc31fe88da020be50493a9402cd87796cf35b33 /compiler/rustc_abi/src/extern_abi/tests.rs | |
| parent | 038c183d5f94b5ca3bed351374b01be4b1c90176 (diff) | |
| download | rust-8abff35b41b8de89da35ab851f931d6a582f7670.tar.gz rust-8abff35b41b8de89da35ab851f931d6a582f7670.zip | |
compiler: compare and hash ExternAbi like its string
Directly map each ExternAbi variant to its string and back again. This has a few advantages: - By making the ABIs compare equal to their strings, we can easily lexicographically sort them and use that sorted slice at runtime. - We no longer need a workaround to make sure the hashes remain stable, as they already naturally are (by being the hashes of unique strings). - The compiler can carry around less &str wide pointers
Diffstat (limited to 'compiler/rustc_abi/src/extern_abi/tests.rs')
| -rw-r--r-- | compiler/rustc_abi/src/extern_abi/tests.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_abi/src/extern_abi/tests.rs b/compiler/rustc_abi/src/extern_abi/tests.rs index 72c0f183d50..44ea58d47c2 100644 --- a/compiler/rustc_abi/src/extern_abi/tests.rs +++ b/compiler/rustc_abi/src/extern_abi/tests.rs @@ -27,3 +27,11 @@ fn indices_are_correct() { assert_eq!(i, abi_data.abi.index()); } } + +#[test] +fn guarantee_lexicographic_ordering() { + let abis = ExternAbi::ALL_VARIANTS; + let mut sorted_abis = abis.to_vec(); + sorted_abis.sort_unstable(); + assert_eq!(abis, sorted_abis); +} |
