]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir/src/hir_id.rs
Rollup merge of #81575 - camelid:rustdoc-wrongnamespace-cleanup, r=jyn514
[rust.git] / compiler / rustc_hir / src / hir_id.rs
index cc8ac4cf5be51bdda772dffefb22e27db3066e05..dd5cddd8525c1bcf5a5b0d59825ae0195fdaabb8 100644 (file)
@@ -18,6 +18,21 @@ pub struct HirId {
     pub local_id: ItemLocalId,
 }
 
+impl HirId {
+    pub fn expect_owner(self) -> LocalDefId {
+        assert_eq!(self.local_id.index(), 0);
+        self.owner
+    }
+
+    pub fn as_owner(self) -> Option<LocalDefId> {
+        if self.local_id.index() == 0 { Some(self.owner) } else { None }
+    }
+
+    pub fn make_owner(owner: LocalDefId) -> Self {
+        Self { owner, local_id: ItemLocalId::from_u32(0) }
+    }
+}
+
 impl fmt::Display for HirId {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "{:?}", self)