@@ -21,44 +21,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
2121use rustc_span:: { ErrorGuaranteed , Span } ;
2222use rustc_target:: spec:: abi:: Abi ;
2323
24- #[ inline]
25- pub fn associated_body ( node : Node < ' _ > ) -> Option < ( LocalDefId , BodyId ) > {
26- match node {
27- Node :: Item ( Item {
28- owner_id,
29- kind : ItemKind :: Const ( _, _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) ,
30- ..
31- } )
32- | Node :: TraitItem ( TraitItem {
33- owner_id,
34- kind :
35- TraitItemKind :: Const ( _, Some ( body) ) | TraitItemKind :: Fn ( _, TraitFn :: Provided ( body) ) ,
36- ..
37- } )
38- | Node :: ImplItem ( ImplItem {
39- owner_id,
40- kind : ImplItemKind :: Const ( _, body) | ImplItemKind :: Fn ( _, body) ,
41- ..
42- } ) => Some ( ( owner_id. def_id , * body) ) ,
43-
44- Node :: Expr ( Expr { kind : ExprKind :: Closure ( Closure { def_id, body, .. } ) , .. } ) => {
45- Some ( ( * def_id, * body) )
46- }
47-
48- Node :: AnonConst ( constant) => Some ( ( constant. def_id , constant. body ) ) ,
49- Node :: ConstBlock ( constant) => Some ( ( constant. def_id , constant. body ) ) ,
50-
51- _ => None ,
52- }
53- }
54-
55- fn is_body_owner ( node : Node < ' _ > , hir_id : HirId ) -> bool {
56- match associated_body ( node) {
57- Some ( ( _, b) ) => b. hir_id == hir_id,
58- None => false ,
59- }
60- }
61-
6224// FIXME: the structure was necessary in the past but now it
6325// only serves as "namespace" for HIR-related methods, and can be
6426// removed if all the methods are reasonably renamed and moved to tcx
@@ -283,7 +245,7 @@ impl<'hir> Map<'hir> {
283245 #[ track_caller]
284246 pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
285247 for ( _, node) in self . parent_iter ( hir_id) {
286- if let Some ( ( def_id, _) ) = associated_body ( node ) {
248+ if let Some ( ( def_id, _) ) = node . associated_body ( ) {
287249 return def_id;
288250 }
289251 }
@@ -296,20 +258,19 @@ impl<'hir> Map<'hir> {
296258 /// item (possibly associated), a closure, or a `hir::AnonConst`.
297259 pub fn body_owner ( self , BodyId { hir_id } : BodyId ) -> HirId {
298260 let parent = self . tcx . parent_hir_id ( hir_id) ;
299- assert ! ( is_body_owner ( self . tcx. hir_node( parent) , hir_id) , "{hir_id:?}" ) ;
261+ assert_eq ! ( self . tcx. hir_node( parent) . body_id ( ) . unwrap ( ) . hir_id , hir_id, "{hir_id:?}" ) ;
300262 parent
301263 }
302264
303265 pub fn body_owner_def_id ( self , BodyId { hir_id } : BodyId ) -> LocalDefId {
304- associated_body ( self . tcx . parent_hir_node ( hir_id) ) . unwrap ( ) . 0
266+ self . tcx . parent_hir_node ( hir_id) . associated_body ( ) . unwrap ( ) . 0
305267 }
306268
307269 /// Given a `LocalDefId`, returns the `BodyId` associated with it,
308270 /// if the node is a body owner, otherwise returns `None`.
309271 pub fn maybe_body_owned_by ( self , id : LocalDefId ) -> Option < BodyId > {
310272 let node = self . tcx . opt_hir_node_by_def_id ( id) ?;
311- let ( _, body_id) = associated_body ( node) ?;
312- Some ( body_id)
273+ node. body_id ( )
313274 }
314275
315276 /// Given a body owner's id, returns the `BodyId` associated with it.
@@ -1322,7 +1283,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13221283 }
13231284
13241285 fn visit_item ( & mut self , item : & ' hir Item < ' hir > ) {
1325- if associated_body ( Node :: Item ( item) ) . is_some ( ) {
1286+ if Node :: Item ( item) . associated_body ( ) . is_some ( ) {
13261287 self . body_owners . push ( item. owner_id . def_id ) ;
13271288 }
13281289
@@ -1363,7 +1324,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13631324 }
13641325
13651326 fn visit_trait_item ( & mut self , item : & ' hir TraitItem < ' hir > ) {
1366- if associated_body ( Node :: TraitItem ( item) ) . is_some ( ) {
1327+ if Node :: TraitItem ( item) . associated_body ( ) . is_some ( ) {
13671328 self . body_owners . push ( item. owner_id . def_id ) ;
13681329 }
13691330
@@ -1372,7 +1333,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13721333 }
13731334
13741335 fn visit_impl_item ( & mut self , item : & ' hir ImplItem < ' hir > ) {
1375- if associated_body ( Node :: ImplItem ( item) ) . is_some ( ) {
1336+ if Node :: ImplItem ( item) . associated_body ( ) . is_some ( ) {
13761337 self . body_owners . push ( item. owner_id . def_id ) ;
13771338 }
13781339
0 commit comments