1
Fork 0

Make node_id_to_hir_id owner-local.

This commit is contained in:
Camille GILLOT 2021-07-18 13:03:53 +02:00 committed by Santiago Pastorino
parent 30b3f35c42
commit 04d5f41c97
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
3 changed files with 53 additions and 36 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`"))