forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#136901 - workingjubilee:stabilize-externabi-hashing-forever, r=compiler-errors compiler: give `ExternAbi` truly stable `Hash` and `Ord` Currently, `ExternAbi` has a bunch of code to handle the reality that, as an enum, adding more variants to it will risk it hashing differently. It forces all of those variants to be added in a fixed order, except this means that the order of the variants doesn't correspond to any logical order except "historical accident". This is all to avoid having to rebless two tests. Perhaps there were more, once upon a time? But then we invented normalization in our test suite to handle exactly this sort of issue in a more general way. There are two options here: - Get rid of all the logical overhead and shrug, embracing blessing a couple of tests sometimes - Change `ExternAbi` to have an ordering and hash that doesn't depend on the number of variants As `ExternAbi` is essentially a strongly-typed string, and thus no two strings can be identical, this implements the second of the two by hand-implementing `Ord` and `Hash` to make the hashing and comparison based on the string! This will diff the current hashes, but they will diff no more after this.
- Loading branch information
Showing
15 changed files
with
163 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,31 @@ | ||
use std::assert_matches::assert_matches; | ||
use std::str::FromStr; | ||
|
||
use super::*; | ||
|
||
#[allow(non_snake_case)] | ||
#[test] | ||
fn lookup_Rust() { | ||
let abi = lookup("Rust"); | ||
assert!(abi.is_ok() && abi.unwrap().data().name == "Rust"); | ||
let abi = ExternAbi::from_str("Rust"); | ||
assert!(abi.is_ok() && abi.unwrap().as_str() == "Rust"); | ||
} | ||
|
||
#[test] | ||
fn lookup_cdecl() { | ||
let abi = lookup("cdecl"); | ||
assert!(abi.is_ok() && abi.unwrap().data().name == "cdecl"); | ||
let abi = ExternAbi::from_str("cdecl"); | ||
assert!(abi.is_ok() && abi.unwrap().as_str() == "cdecl"); | ||
} | ||
|
||
#[test] | ||
fn lookup_baz() { | ||
let abi = lookup("baz"); | ||
assert_matches!(abi, Err(AbiUnsupported {})); | ||
let abi = ExternAbi::from_str("baz"); | ||
assert_matches!(abi, Err(AbiFromStrErr::Unknown)); | ||
} | ||
|
||
#[test] | ||
fn indices_are_correct() { | ||
for (i, abi_data) in AbiDatas.iter().enumerate() { | ||
assert_eq!(i, abi_data.abi.index()); | ||
} | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.