Skip to content

Commit 0c68b7a

Browse files
committed
Update body_owner and maybe_body_owned_by
1 parent d3c7394 commit 0c68b7a

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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::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+
},
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::Fn(_, 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

@@ -455,7 +453,7 @@ impl<'hir> Map<'hir> {
455453
/// item (possibly associated), a closure, or a `hir::AnonConst`.
456454
pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId {
457455
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)));
459457
parent
460458
}
461459

@@ -466,14 +464,8 @@ impl<'hir> Map<'hir> {
466464
/// Given a `HirId`, returns the `BodyId` associated with it,
467465
/// if the node is a body owner, otherwise returns `None`.
468466
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)
477469
} else {
478470
bug!("no entry for id `{}`", hir_id)
479471
}

0 commit comments

Comments
 (0)