1
Fork 0

Auto merge of #126326 - eggyal:ununsafe-StableOrd, r=michaelwoerister

Un-unsafe the `StableOrd` trait

Whilst incorrect implementations of this trait can cause miscompilation, they cannot cause memory unsafety in rustc.

[Discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Policy.20of.20.60unsafe.60.20within.20the.20compiler).

cc [MCP 533](https://github.com/rust-lang/compiler-team/issues/533), #105175, `@michaelwoerister`

r? `@Nilstrieb`
This commit is contained in:
bors 2024-06-25 15:51:35 +00:00
commit c290e9de32
6 changed files with 76 additions and 28 deletions

View file

@ -165,10 +165,12 @@ impl ItemLocalId {
pub const INVALID: ItemLocalId = ItemLocalId::MAX;
}
// Safety: Ord is implement as just comparing the ItemLocalId's numerical
// values and these are not changed by (de-)serialization.
unsafe impl StableOrd for ItemLocalId {
impl StableOrd for ItemLocalId {
const CAN_USE_UNSTABLE_SORT: bool = true;
// `Ord` is implemented as just comparing the ItemLocalId's numerical
// values and these are not changed by (de-)serialization.
const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = ();
}
/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`.