@@ -94,43 +94,41 @@ fn fn_sig<'hir>(node: Node<'hir>) -> Option<&'hir FnSig<'hir>> {
94
94
}
95
95
}
96
96
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 :: Fn ( _, 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
+ } ,
112
105
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 :: Fn ( _, TraitMethod :: Provided ( body) ) => Some ( body) ,
109
+ _ => None ,
110
+ } ,
117
111
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
+ } ,
119
116
120
- Node :: Expr ( expr) => match expr. kind {
121
- ExprKind :: Closure ( .., body, _, _) => Some ( body) ,
122
- _ => None ,
123
- } ,
117
+ Node :: AnonConst ( constant) => Some ( constant. body ) ,
124
118
119
+ Node :: Expr ( expr) => match expr. kind {
120
+ ExprKind :: Closure ( .., body, _, _) => Some ( body) ,
125
121
_ => None ,
126
- }
122
+ } ,
123
+
124
+ _ => None ,
127
125
}
126
+ }
128
127
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 ,
134
132
}
135
133
}
136
134
@@ -455,7 +453,7 @@ impl<'hir> Map<'hir> {
455
453
/// item (possibly associated), a closure, or a `hir::AnonConst`.
456
454
pub fn body_owner ( & self , BodyId { hir_id } : BodyId ) -> HirId {
457
455
let parent = self . get_parent_node ( hir_id) ;
458
- assert ! ( self . lookup ( parent) . map_or( false , |e| e . is_body_owner( hir_id) ) ) ;
456
+ assert ! ( self . find ( parent) . map_or( false , |n| is_body_owner( n , hir_id) ) ) ;
459
457
parent
460
458
}
461
459
@@ -466,14 +464,8 @@ impl<'hir> Map<'hir> {
466
464
/// Given a `HirId`, returns the `BodyId` associated with it,
467
465
/// if the node is a body owner, otherwise returns `None`.
468
466
pub fn maybe_body_owned_by ( & self , hir_id : HirId ) -> Option < BodyId > {
469
- if let Some ( entry) = self . find_entry ( hir_id) {
470
- if self . dep_graph . is_fully_enabled ( ) {
471
- let hir_id_owner = hir_id. owner ;
472
- let def_path_hash = self . definitions . def_path_hash ( hir_id_owner) ;
473
- self . dep_graph . read ( def_path_hash. to_dep_node ( DepKind :: HirBody ) ) ;
474
- }
475
-
476
- entry. associated_body ( )
467
+ if let Some ( node) = self . find ( hir_id) {
468
+ associated_body ( node)
477
469
} else {
478
470
bug ! ( "no entry for id `{}`" , hir_id)
479
471
}
0 commit comments