@@ -20,44 +20,6 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
2020use rustc_span:: { ErrorGuaranteed , Span } ;
2121use rustc_target:: spec:: abi:: Abi ;
2222
23- #[ inline]
24- pub fn associated_body ( node : Node < ' _ > ) -> Option < ( LocalDefId , BodyId ) > {
25- match node {
26- Node :: Item ( Item {
27- owner_id,
28- kind : ItemKind :: Const ( _, _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) ,
29- ..
30- } )
31- | Node :: TraitItem ( TraitItem {
32- owner_id,
33- kind :
34- TraitItemKind :: Const ( _, Some ( body) ) | TraitItemKind :: Fn ( _, TraitFn :: Provided ( body) ) ,
35- ..
36- } )
37- | Node :: ImplItem ( ImplItem {
38- owner_id,
39- kind : ImplItemKind :: Const ( _, body) | ImplItemKind :: Fn ( _, body) ,
40- ..
41- } ) => Some ( ( owner_id. def_id , * body) ) ,
42-
43- Node :: Expr ( Expr { kind : ExprKind :: Closure ( Closure { def_id, body, .. } ) , .. } ) => {
44- Some ( ( * def_id, * body) )
45- }
46-
47- Node :: AnonConst ( constant) => Some ( ( constant. def_id , constant. body ) ) ,
48- Node :: ConstBlock ( constant) => Some ( ( constant. def_id , constant. body ) ) ,
49-
50- _ => None ,
51- }
52- }
53-
54- fn is_body_owner ( node : Node < ' _ > , hir_id : HirId ) -> bool {
55- match associated_body ( node) {
56- Some ( ( _, b) ) => b. hir_id == hir_id,
57- None => false ,
58- }
59- }
60-
6123// FIXME: the structure was necessary in the past but now it
6224// only serves as "namespace" for HIR-related methods, and can be
6325// removed if all the methods are reasonably renamed and moved to tcx
@@ -273,7 +235,7 @@ impl<'hir> Map<'hir> {
273235 #[ track_caller]
274236 pub fn enclosing_body_owner ( self , hir_id : HirId ) -> LocalDefId {
275237 for ( _, node) in self . parent_iter ( hir_id) {
276- if let Some ( ( def_id, _) ) = associated_body ( node ) {
238+ if let Some ( ( def_id, _) ) = node . associated_body ( ) {
277239 return def_id;
278240 }
279241 }
@@ -286,20 +248,18 @@ impl<'hir> Map<'hir> {
286248 /// item (possibly associated), a closure, or a `hir::AnonConst`.
287249 pub fn body_owner ( self , BodyId { hir_id } : BodyId ) -> HirId {
288250 let parent = self . tcx . parent_hir_id ( hir_id) ;
289- assert ! ( is_body_owner ( self . tcx. hir_node( parent) , hir_id) , "{hir_id:?}" ) ;
251+ assert_eq ! ( self . tcx. hir_node( parent) . body_id ( ) . unwrap ( ) . hir_id , hir_id, "{hir_id:?}" ) ;
290252 parent
291253 }
292254
293255 pub fn body_owner_def_id ( self , BodyId { hir_id } : BodyId ) -> LocalDefId {
294- associated_body ( self . tcx . parent_hir_node ( hir_id) ) . unwrap ( ) . 0
256+ self . tcx . parent_hir_node ( hir_id) . associated_body ( ) . unwrap ( ) . 0
295257 }
296258
297259 /// Given a `LocalDefId`, returns the `BodyId` associated with it,
298260 /// if the node is a body owner, otherwise returns `None`.
299261 pub fn maybe_body_owned_by ( self , id : LocalDefId ) -> Option < BodyId > {
300- let node = self . tcx . hir_node_by_def_id ( id) ;
301- let ( _, body_id) = associated_body ( node) ?;
302- Some ( body_id)
262+ self . tcx . hir_node_by_def_id ( id) . body_id ( )
303263 }
304264
305265 /// Given a body owner's id, returns the `BodyId` associated with it.
@@ -1314,7 +1274,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13141274 }
13151275
13161276 fn visit_item ( & mut self , item : & ' hir Item < ' hir > ) {
1317- if associated_body ( Node :: Item ( item) ) . is_some ( ) {
1277+ if Node :: Item ( item) . associated_body ( ) . is_some ( ) {
13181278 self . body_owners . push ( item. owner_id . def_id ) ;
13191279 }
13201280
@@ -1355,7 +1315,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13551315 }
13561316
13571317 fn visit_trait_item ( & mut self , item : & ' hir TraitItem < ' hir > ) {
1358- if associated_body ( Node :: TraitItem ( item) ) . is_some ( ) {
1318+ if Node :: TraitItem ( item) . associated_body ( ) . is_some ( ) {
13591319 self . body_owners . push ( item. owner_id . def_id ) ;
13601320 }
13611321
@@ -1364,7 +1324,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
13641324 }
13651325
13661326 fn visit_impl_item ( & mut self , item : & ' hir ImplItem < ' hir > ) {
1367- if associated_body ( Node :: ImplItem ( item) ) . is_some ( ) {
1327+ if Node :: ImplItem ( item) . associated_body ( ) . is_some ( ) {
13681328 self . body_owners . push ( item. owner_id . def_id ) ;
13691329 }
13701330
0 commit comments