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.
This commit is contained in:
bors 2022-12-06 09:21:49 +00:00
commit 9db224fc90
7 changed files with 95 additions and 35 deletions

View file

@ -10,7 +10,7 @@ use crate::{lint, HashStableContext};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::ToStableHashKey;
use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
use rustc_target::abi::Align;
use rustc_target::spec::{PanicStrategy, SanitizerSet, SplitDebuginfo};
use rustc_target::spec::{Target, TargetTriple, TargetWarnings, TARGETS};
@ -288,6 +288,9 @@ pub enum OutputType {
DepInfo,
}
// Safety: Trivial C-Style enums have a stable sort order across compilation sessions.
unsafe impl StableOrd for OutputType {}
impl<HCX: HashStableContext> ToStableHashKey<HCX> for OutputType {
type KeyType = Self;