diff options
author | bors <bors@rust-lang.org> | 2022-12-06 09:21:49 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2022-12-06 09:21:49 +0000 |
commit | 9db224fc908059986c179fc6ec433944e9cfce50 (patch) | |
tree | 1d7ea6499772331aeb35a1b4cebb1c7e18c46d19 /compiler/rustc_abi | |
parent | c5351ad4dcd9f3d73241b2acbfc6b4631da845c5 (diff) | |
parent | 56aacb245ce484994ac2e0ecab72b477ad6dc362 (diff) | |
download | rust-9db224fc908059986c179fc6ec433944e9cfce50.tar.gz |
Auto merge of #105175 - michaelwoerister:add-stable-ord-trait, r=nagisa
Add StableOrd trait as proposed in MCP 533.
The `StableOrd` trait can be used to mark types as having a stable sort order across compilation sessions. Collections that sort their items in a stable way can safely implement HashStable by hashing items in sort order.
See https://github.com/rust-lang/compiler-team/issues/533 for more information.
Diffstat (limited to 'compiler/rustc_abi')
-rw-r--r-- | compiler/rustc_abi/src/lib.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_abi/src/lib.rs b/compiler/rustc_abi/src/lib.rs index 85693259cd0..e14c9ea9a5d 100644 --- a/compiler/rustc_abi/src/lib.rs +++ b/compiler/rustc_abi/src/lib.rs @@ -9,6 +9,8 @@ use std::ops::{Add, AddAssign, Mul, RangeInclusive, Sub}; use std::str::FromStr; use bitflags::bitflags; +#[cfg(feature = "nightly")] +use rustc_data_structures::stable_hasher::StableOrd; use rustc_index::vec::{Idx, IndexVec}; #[cfg(feature = "nightly")] use rustc_macros::HashStable_Generic; @@ -403,6 +405,11 @@ pub struct Size { raw: u64, } +// Safety: Ord is implement as just comparing numerical values and numerical values +// are not changed by (de-)serialization. +#[cfg(feature = "nightly")] +unsafe impl StableOrd for Size {} + // This is debug-printed a lot in larger structs, don't waste too much space there impl fmt::Debug for Size { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |