about summary refs log tree commit diff
path: root/compiler/rustc_hir/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-02-24 01:26:57 +0000
committerbors <bors@rust-lang.org>2022-02-24 01:26:57 +0000
commit8ebec97e09a89760e5791bbb2ab96e2ebec19931 (patch)
treee3cee787918871b396f89729ca53f8d97a051f26 /compiler/rustc_hir/src
parent532d3cda90b8a729cd982548649d32803d265052 (diff)
parentd82a7bc1b5615548811d2c50cc64f6d486ef1d02 (diff)
downloadrust-8ebec97e09a89760e5791bbb2ab96e2ebec19931.tar.gz
rust-8ebec97e09a89760e5791bbb2ab96e2ebec19931.zip
Auto merge of #93438 - spastorino:node_id_to_hir_id_refactor, r=oli-obk
Node id to hir id refactor

Related to #89278

r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_hir/src')
-rw-r--r--compiler/rustc_hir/src/def.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs
index e99f61d034f..a2f97f65708 100644
--- a/compiler/rustc_hir/src/def.rs
+++ b/compiler/rustc_hir/src/def.rs
@@ -611,6 +611,19 @@ impl<Id> Res<Id> {
         }
     }
 
+    pub fn apply_id<R, E>(self, mut map: impl FnMut(Id) -> Result<R, E>) -> Result<Res<R>, E> {
+        Ok(match self {
+            Res::Def(kind, id) => Res::Def(kind, id),
+            Res::SelfCtor(id) => Res::SelfCtor(id),
+            Res::PrimTy(id) => Res::PrimTy(id),
+            Res::Local(id) => Res::Local(map(id)?),
+            Res::SelfTy { trait_, alias_to } => Res::SelfTy { trait_, alias_to },
+            Res::ToolMod => Res::ToolMod,
+            Res::NonMacroAttr(attr_kind) => Res::NonMacroAttr(attr_kind),
+            Res::Err => Res::Err,
+        })
+    }
+
     #[track_caller]
     pub fn expect_non_local<OtherId>(self) -> Res<OtherId> {
         self.map_id(|_| panic!("unexpected `Res::Local`"))