@@ -170,6 +170,7 @@ impl<'hir> Map<'hir> {
170
170
}
171
171
172
172
#[ inline]
173
+ #[ track_caller]
173
174
pub fn local_def_id ( self , hir_id : HirId ) -> LocalDefId {
174
175
self . opt_local_def_id ( hir_id) . unwrap_or_else ( || {
175
176
bug ! (
@@ -310,6 +311,7 @@ impl<'hir> Map<'hir> {
310
311
}
311
312
}
312
313
314
+ #[ track_caller]
313
315
pub fn get_parent_node ( self , hir_id : HirId ) -> HirId {
314
316
self . find_parent_node ( hir_id)
315
317
. unwrap_or_else ( || bug ! ( "No parent for node {:?}" , self . node_to_string( hir_id) ) )
@@ -334,12 +336,14 @@ impl<'hir> Map<'hir> {
334
336
}
335
337
336
338
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
339
+ #[ track_caller]
337
340
pub fn get ( self , id : HirId ) -> Node < ' hir > {
338
341
self . find ( id) . unwrap_or_else ( || bug ! ( "couldn't find hir id {} in the HIR map" , id) )
339
342
}
340
343
341
344
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
342
345
#[ inline]
346
+ #[ track_caller]
343
347
pub fn get_by_def_id ( self , id : LocalDefId ) -> Node < ' hir > {
344
348
self . find_by_def_id ( id) . unwrap_or_else ( || bug ! ( "couldn't find {:?} in the HIR map" , id) )
345
349
}
@@ -377,6 +381,7 @@ impl<'hir> Map<'hir> {
377
381
self . tcx . hir_owner_nodes ( id. hir_id . owner ) . unwrap ( ) . bodies [ & id. hir_id . local_id ]
378
382
}
379
383
384
+ #[ track_caller]
380
385
pub fn fn_decl_by_hir_id ( self , hir_id : HirId ) -> Option < & ' hir FnDecl < ' hir > > {
381
386
if let Some ( node) = self . find ( hir_id) {
382
387
node. fn_decl ( )
@@ -385,6 +390,7 @@ impl<'hir> Map<'hir> {
385
390
}
386
391
}
387
392
393
+ #[ track_caller]
388
394
pub fn fn_sig_by_hir_id ( self , hir_id : HirId ) -> Option < & ' hir FnSig < ' hir > > {
389
395
if let Some ( node) = self . find ( hir_id) {
390
396
node. fn_sig ( )
@@ -393,6 +399,7 @@ impl<'hir> Map<'hir> {
393
399
}
394
400
}
395
401
402
+ #[ track_caller]
396
403
pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
397
404
for ( _, node) in self . parent_iter ( hir_id) {
398
405
if let Some ( body) = associated_body ( node) {
@@ -408,7 +415,7 @@ impl<'hir> Map<'hir> {
408
415
/// item (possibly associated), a closure, or a `hir::AnonConst`.
409
416
pub fn body_owner ( self , BodyId { hir_id } : BodyId ) -> HirId {
410
417
let parent = self . get_parent_node ( hir_id) ;
411
- assert ! ( self . find( parent) . map_or( false , |n| is_body_owner( n, hir_id) ) ) ;
418
+ assert ! ( self . find( parent) . map_or( false , |n| is_body_owner( n, hir_id) ) , "{hir_id:?}" ) ;
412
419
parent
413
420
}
414
421
@@ -419,10 +426,11 @@ impl<'hir> Map<'hir> {
419
426
/// Given a `LocalDefId`, returns the `BodyId` associated with it,
420
427
/// if the node is a body owner, otherwise returns `None`.
421
428
pub fn maybe_body_owned_by ( self , id : LocalDefId ) -> Option < BodyId > {
422
- self . get_if_local ( id. to_def_id ( ) ) . map ( associated_body) . flatten ( )
429
+ self . find_by_def_id ( id) . and_then ( associated_body)
423
430
}
424
431
425
432
/// Given a body owner's id, returns the `BodyId` associated with it.
433
+ #[ track_caller]
426
434
pub fn body_owned_by ( self , id : LocalDefId ) -> BodyId {
427
435
self . maybe_body_owned_by ( id) . unwrap_or_else ( || {
428
436
let hir_id = self . local_def_id_to_hir_id ( id) ;
0 commit comments