Some track_caller additions

This commit is contained in:
Oli Scherer 2022-10-12 14:16:31 +00:00
parent b0ed631ad4
commit b2b859be8c

View File

@ -170,6 +170,7 @@ pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
} }
#[inline] #[inline]
#[track_caller]
pub fn local_def_id(self, hir_id: HirId) -> LocalDefId { pub fn local_def_id(self, hir_id: HirId) -> LocalDefId {
self.opt_local_def_id(hir_id).unwrap_or_else(|| { self.opt_local_def_id(hir_id).unwrap_or_else(|| {
bug!( bug!(
@ -310,6 +311,7 @@ pub fn find_parent_node(self, id: HirId) -> Option<HirId> {
} }
} }
#[track_caller]
pub fn get_parent_node(self, hir_id: HirId) -> HirId { pub fn get_parent_node(self, hir_id: HirId) -> HirId {
self.find_parent_node(hir_id) self.find_parent_node(hir_id)
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id))) .unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
@ -334,12 +336,14 @@ pub fn find_by_def_id(self, id: LocalDefId) -> Option<Node<'hir>> {
} }
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
#[track_caller]
pub fn get(self, id: HirId) -> Node<'hir> { pub fn get(self, id: HirId) -> Node<'hir> {
self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id))
} }
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
#[inline] #[inline]
#[track_caller]
pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> { pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> {
self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id)) self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id))
} }
@ -377,6 +381,7 @@ pub fn body(self, id: BodyId) -> &'hir Body<'hir> {
self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id] self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id]
} }
#[track_caller]
pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
if let Some(node) = self.find(hir_id) { if let Some(node) = self.find(hir_id) {
node.fn_decl() node.fn_decl()
@ -385,6 +390,7 @@ pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> {
} }
} }
#[track_caller]
pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> { pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
if let Some(node) = self.find(hir_id) { if let Some(node) = self.find(hir_id) {
node.fn_sig() node.fn_sig()
@ -393,6 +399,7 @@ pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> {
} }
} }
#[track_caller]
pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId { pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId {
for (_, node) in self.parent_iter(hir_id) { for (_, node) in self.parent_iter(hir_id) {
if let Some(body) = associated_body(node) { if let Some(body) = associated_body(node) {
@ -423,6 +430,7 @@ pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option<BodyId> {
} }
/// Given a body owner's id, returns the `BodyId` associated with it. /// Given a body owner's id, returns the `BodyId` associated with it.
#[track_caller]
pub fn body_owned_by(self, id: LocalDefId) -> BodyId { pub fn body_owned_by(self, id: LocalDefId) -> BodyId {
self.maybe_body_owned_by(id).unwrap_or_else(|| { self.maybe_body_owned_by(id).unwrap_or_else(|| {
let hir_id = self.local_def_id_to_hir_id(id); let hir_id = self.local_def_id_to_hir_id(id);