diff options
Diffstat (limited to 'compiler/rustc_span/src/def_id.rs')
-rw-r--r-- | compiler/rustc_span/src/def_id.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 7c5e1427d..162c15574 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -119,6 +119,12 @@ impl DefPathHash { } } +impl Default for DefPathHash { + fn default() -> Self { + DefPathHash(Fingerprint::ZERO) + } +} + impl Borrow<Fingerprint> for DefPathHash { #[inline] fn borrow(&self) -> &Fingerprint { @@ -229,7 +235,7 @@ impl<D: Decoder> Decodable<D> for DefIndex { pub struct DefId { // cfg-ing the order of fields so that the `DefIndex` which is high entropy always ends up in // the lower bits no matter the endianness. This allows the compiler to turn that `Hash` impl - // into a direct call to 'u64::hash(_)`. + // into a direct call to `u64::hash(_)`. #[cfg(not(all(target_pointer_width = "64", target_endian = "big")))] pub index: DefIndex, pub krate: CrateNum, @@ -293,7 +299,7 @@ impl DefId { #[inline] pub fn as_local(self) -> Option<LocalDefId> { - if self.is_local() { Some(LocalDefId { local_def_index: self.index }) } else { None } + self.is_local().then(|| LocalDefId { local_def_index: self.index }) } #[inline] @@ -314,7 +320,7 @@ impl DefId { #[inline] pub fn as_crate_root(self) -> Option<CrateNum> { - if self.is_crate_root() { Some(self.krate) } else { None } + self.is_crate_root().then_some(self.krate) } #[inline] |