Skip to content

Commit c7e1f4d

Browse files
committed
HIR: remove the NodeId get_parent_node, HirIdify is_argument
1 parent 85ed21e commit c7e1f4d

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/librustc/hir/map/mod.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -615,23 +615,16 @@ impl<'hir> Map<'hir> {
615615
result
616616
}
617617

618-
/// Similar to `get_parent`; returns the parent node-ID, or just `hir_id` if there
619-
/// is no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself
618+
/// Similar to `get_parent`; returns the parent HIR Id, or just `hir_id` if there
619+
/// is no parent. Note that the parent may be `CRATE_HIR_ID`, which is not itself
620620
/// present in the map, so passing the return value of `get_parent_node` to
621621
/// `get` may in fact panic.
622-
/// This function returns the immediate parent in the AST, whereas `get_parent`
622+
/// This function returns the immediate parent in the HIR, whereas `get_parent`
623623
/// returns the enclosing item. Note that this might not be the actual parent
624-
/// node in the AST -- some kinds of nodes are not in the map and these will
624+
/// node in the HIR -- some kinds of nodes are not in the map and these will
625625
/// never appear as the parent node. Thus, you can always walk the parent nodes
626-
/// from a node to the root of the AST (unless you get back the same ID here,
626+
/// from a node to the root of the HIR (unless you get back the same ID here,
627627
/// which can happen if the ID is not in the map itself or is just weird).
628-
pub fn get_parent_node(&self, id: NodeId) -> NodeId {
629-
let hir_id = self.node_to_hir_id(id);
630-
let parent_hir_id = self.get_parent_node_by_hir_id(hir_id);
631-
self.hir_to_node_id(parent_hir_id)
632-
}
633-
634-
// FIXME(@ljedrz): replace the `NodeId` variant.
635628
pub fn get_parent_node_by_hir_id(&self, hir_id: HirId) -> HirId {
636629
if self.dep_graph.is_fully_enabled() {
637630
let hir_id_owner = hir_id.owner;
@@ -646,12 +639,12 @@ impl<'hir> Map<'hir> {
646639

647640
/// Check if the node is an argument. An argument is a local variable whose
648641
/// immediate parent is an item or a closure.
649-
pub fn is_argument(&self, id: NodeId) -> bool {
650-
match self.find(id) {
642+
pub fn is_argument(&self, id: HirId) -> bool {
643+
match self.find_by_hir_id(id) {
651644
Some(Node::Binding(_)) => (),
652645
_ => return false,
653646
}
654-
match self.find(self.get_parent_node(id)) {
647+
match self.find_by_hir_id(self.get_parent_node_by_hir_id(id)) {
655648
Some(Node::Item(_)) |
656649
Some(Node::TraitItem(_)) |
657650
Some(Node::ImplItem(_)) => true,

src/librustc/middle/mem_categorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ impl<'tcx> cmt_<'tcx> {
15261526
"non-place".into()
15271527
}
15281528
Categorization::Local(vid) => {
1529-
if tcx.hir().is_argument(tcx.hir().hir_to_node_id(vid)) {
1529+
if tcx.hir().is_argument(vid) {
15301530
"argument"
15311531
} else {
15321532
"local variable"

src/librustc_save_analysis/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
621621
Node::PathSegment(seg) => {
622622
match seg.res {
623623
Some(res) if res != Res::Err => res,
624-
_ => self.get_path_res(self.tcx.hir().get_parent_node(id)),
624+
_ => {
625+
let parent_node = self.tcx.hir().get_parent_node_by_hir_id(hir_id);
626+
self.get_path_res(self.tcx.hir().hir_to_node_id(parent_node))
627+
},
625628
}
626629
}
627630

0 commit comments

Comments
 (0)