From 5a123c265b7bf47fb7894c9e338f531fb463b4d8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 5 Dec 2021 11:18:16 +0100 Subject: [PATCH] Add fast path to `opt_local_def_id`. --- compiler/rustc_middle/src/hir/map/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 394a1fc2270..30c75f35fc3 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -200,8 +200,12 @@ impl<'hir> Map<'hir> { #[inline] pub fn opt_local_def_id(&self, hir_id: HirId) -> Option { - // FIXME(#85914) is this access safe for incr. comp.? - self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id) + if hir_id.local_id == ItemLocalId::new(0) { + Some(hir_id.owner) + } else { + // FIXME(#85914) is this access safe for incr. comp.? + self.tcx.untracked_resolutions.definitions.opt_hir_id_to_local_def_id(hir_id) + } } #[inline]