Skip to content

Commit 0d7cae3

Browse files
committed
Use get_parent_did to access parent hir_id instead of DefIdTree::parent
Fixes rust-lang#71820
1 parent 34d6b44 commit 0d7cae3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/librustc_privacy/lib.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -941,27 +941,21 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
941941
return;
942942
}
943943

944-
let macro_module_def_id =
945-
ty::DefIdTree::parent(self.tcx, self.tcx.hir().local_def_id(md.hir_id).to_def_id())
946-
.unwrap();
947-
// FIXME(#71104) Should really be using just `as_local_hir_id` but
948-
// some `DefId` do not seem to have a corresponding HirId.
949-
let hir_id = macro_module_def_id
950-
.as_local()
951-
.and_then(|def_id| self.tcx.hir().opt_local_def_id_to_hir_id(def_id));
952-
let mut module_id = match hir_id {
953-
Some(module_id) if self.tcx.hir().is_hir_id_module(module_id) => module_id,
944+
let macro_module_def_id = self.tcx.hir().get_parent_did(md.hir_id);
945+
let mut module_id = self.tcx.hir().as_local_hir_id(macro_module_def_id);
946+
if !self.tcx.hir().is_hir_id_module(module_id) {
954947
// `module_id` doesn't correspond to a `mod`, return early (#63164, #65252).
955-
_ => return,
956-
};
948+
return;
949+
}
957950
let level = if md.vis.node.is_pub() { self.get(module_id) } else { None };
958951
let new_level = self.update(md.hir_id, level);
959952
if new_level.is_none() {
960953
return;
961954
}
962955

963956
loop {
964-
let changed_reachability = self.update_macro_reachable(module_id, macro_module_def_id);
957+
let changed_reachability =
958+
self.update_macro_reachable(module_id, macro_module_def_id.to_def_id());
965959
if changed_reachability || module_id == hir::CRATE_HIR_ID {
966960
break;
967961
}

0 commit comments

Comments
 (0)