1
Fork 0

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`
This commit is contained in:
bors 2022-02-24 01:26:57 +00:00
commit 8ebec97e09
3 changed files with 74 additions and 59 deletions

View file

@ -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`"))