X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_metadata%2Fsrc%2Frmeta%2Ftable.rs;h=99bec570600a0faae76c4afb1479ce834e1702c1;hb=6d225bb0804e333aa411acce45de4230845bcf2b;hp=11916553db5141465846e9ca511ca1a16c791b69;hpb=eb5f2d3980aa80fd91173401b167d55ec431a512;p=rust.git diff --git a/compiler/rustc_metadata/src/rmeta/table.rs b/compiler/rustc_metadata/src/rmeta/table.rs index 11916553db5..99bec570600 100644 --- a/compiler/rustc_metadata/src/rmeta/table.rs +++ b/compiler/rustc_metadata/src/rmeta/table.rs @@ -44,6 +44,12 @@ fn is_default(&self) -> bool { } } +impl IsDefault for DefPathHash { + fn is_default(&self) -> bool { + self.0 == Fingerprint::ZERO + } +} + /// Helper trait, for encoding to, and decoding from, a fixed number of bytes. /// Used mainly for Lazy positions and lengths. /// Unchecked invariant: `Self::default()` should encode as `[0; BYTE_LEN]`, @@ -191,21 +197,18 @@ impl FixedSizeEncoding for Option<$ty> { } // We directly encode `DefPathHash` because a `LazyValue` would incur a 25% cost. -impl FixedSizeEncoding for Option { +impl FixedSizeEncoding for DefPathHash { type ByteArray = [u8; 16]; #[inline] fn from_bytes(b: &[u8; 16]) -> Self { - // NOTE: There's a collision between `None` and `Some(0)`. - Some(DefPathHash(Fingerprint::from_le_bytes(*b))) + DefPathHash(Fingerprint::from_le_bytes(*b)) } #[inline] fn write_to_bytes(self, b: &mut [u8; 16]) { - match self { - None => unreachable!(), - Some(DefPathHash(fingerprint)) => *b = fingerprint.to_le_bytes(), - } + debug_assert!(!self.is_default()); + *b = self.0.to_le_bytes(); } }