@@ -94,43 +94,41 @@ fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
9494 }
9595}
9696
97- impl < ' hir > Entry < ' hir > {
98- fn associated_body ( self ) -> Option < BodyId > {
99- match self . node {
100- Node :: Item ( item) => match item. kind {
101- ItemKind :: Const ( _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) => {
102- Some ( body)
103- }
104- _ => None ,
105- } ,
106-
107- Node :: TraitItem ( item) => match item. kind {
108- TraitItemKind :: Const ( _, Some ( body) )
109- | TraitItemKind :: Method ( _, TraitMethod :: Provided ( body) ) => Some ( body) ,
110- _ => None ,
111- } ,
97+ fn associated_body < ' hir > ( node : Node < ' hir > ) -> Option < BodyId > {
98+ match node {
99+ Node :: Item ( item) => match item. kind {
100+ ItemKind :: Const ( _, body) | ItemKind :: Static ( .., body) | ItemKind :: Fn ( .., body) => {
101+ Some ( body)
102+ }
103+ _ => None ,
104+ } ,
112105
113- Node :: ImplItem ( item) => match item. kind {
114- ImplItemKind :: Const ( _, body) | ImplItemKind :: Method ( _, body) => Some ( body) ,
115- _ => None ,
116- } ,
106+ Node :: TraitItem ( item) => match item. kind {
107+ TraitItemKind :: Const ( _, Some ( body) )
108+ | TraitItemKind :: Method ( _, TraitMethod :: Provided ( body) ) => Some ( body) ,
109+ _ => None ,
110+ } ,
117111
118- Node :: AnonConst ( constant) => Some ( constant. body ) ,
112+ Node :: ImplItem ( item) => match item. kind {
113+ ImplItemKind :: Const ( _, body) | ImplItemKind :: Method ( _, body) => Some ( body) ,
114+ _ => None ,
115+ } ,
119116
120- Node :: Expr ( expr) => match expr. kind {
121- ExprKind :: Closure ( .., body, _, _) => Some ( body) ,
122- _ => None ,
123- } ,
117+ Node :: AnonConst ( constant) => Some ( constant. body ) ,
124118
119+ Node :: Expr ( expr) => match expr. kind {
120+ ExprKind :: Closure ( .., body, _, _) => Some ( body) ,
125121 _ => None ,
126- }
122+ } ,
123+
124+ _ => None ,
127125 }
126+ }
128127
129- fn is_body_owner ( self , hir_id : HirId ) -> bool {
130- match self . associated_body ( ) {
131- Some ( b) => b. hir_id == hir_id,
132- None => false ,
133- }
128+ fn is_body_owner < ' hir > ( node : Node < ' hir > , hir_id : HirId ) -> bool {
129+ match associated_body ( node) {
130+ Some ( b) => b. hir_id == hir_id,
131+ None => false ,
134132 }
135133}
136134
@@ -460,7 +458,7 @@ impl<'hir> Map<'hir> {
460458 /// item (possibly associated), a closure, or a `hir::AnonConst`.
461459 pub fn body_owner ( & self , BodyId { hir_id } : BodyId ) -> HirId {
462460 let parent = self . get_parent_node ( hir_id) ;
463- assert ! ( self . lookup ( parent) . map_or( false , |e| e . is_body_owner( hir_id) ) ) ;
461+ assert ! ( self . find ( parent) . map_or( false , |n| is_body_owner( n , hir_id) ) ) ;
464462 parent
465463 }
466464
@@ -471,14 +469,8 @@ impl<'hir> Map<'hir> {
471469 /// Given a `HirId`, returns the `BodyId` associated with it,
472470 /// if the node is a body owner, otherwise returns `None`.
473471 pub fn maybe_body_owned_by ( & self , hir_id : HirId ) -> Option < BodyId > {
474- if let Some ( entry) = self . find_entry ( hir_id) {
475- if self . dep_graph . is_fully_enabled ( ) {
476- let hir_id_owner = hir_id. owner ;
477- let def_path_hash = self . definitions . def_path_hash ( hir_id_owner) ;
478- self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: HirBody ) ) ;
479- }
480-
481- entry. associated_body ( )
472+ if let Some ( node) = self . find ( hir_id) {
473+ associated_body ( node)
482474 } else {
483475 bug ! ( "no entry for id `{}`" , hir_id)
484476 }
0 commit comments