diff --git a/src/lib.rs b/src/lib.rs index 7d8eb92ac58..22869e9b248 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,6 +17,7 @@ clippy::single_match, clippy::useless_format, clippy::derive_partial_eq_without_eq, + clippy::derive_hash_xor_eq, clippy::too_many_arguments )] diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index 0d671ec653b..88d1b1f1052 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -27,12 +27,30 @@ pub type CallId = NonZeroU64; pub type AllocExtra = Stacks; /// Tracking pointer provenance -#[derive(Copy, Clone, Hash, PartialEq, Eq)] +#[derive(Copy, Clone, Hash, Eq)] pub enum SbTag { Tagged(PtrId), Untagged, } +impl SbTag { + fn as_u64(self) -> u64 { + match self { + SbTag::Tagged(id) => id.get(), + SbTag::Untagged => 0, + } + } +} + +impl PartialEq for SbTag { + fn eq(&self, other: &Self) -> bool { + // The codegen for the derived Partialeq is bad here and includes a branch. + // Since this code is extremely hot, this is optimized here. + // https://github.com/rust-lang/rust/issues/49892 + self.as_u64() == other.as_u64() + } +} + impl fmt::Debug for SbTag { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self {