Skip to content

Commit a64456e

Browse files
committed
remove hir::map::get
1 parent ae72c91 commit a64456e

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

src/librustc/hir/map/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,20 +561,14 @@ impl<'hir> Map<'hir> {
561561
}
562562

563563
/// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
564-
pub fn get(&self, id: NodeId) -> Node<'hir> {
565-
let hir_id = self.node_to_hir_id(id);
566-
self.get_by_hir_id(hir_id)
567-
}
568-
569-
// FIXME(@ljedrz): replace the `NodeId` variant.
570564
pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> {
571565
// read recorded by `find`
572566
self.find_by_hir_id(id).unwrap_or_else(||
573567
bug!("couldn't find hir id {} in the HIR map", id))
574568
}
575569

576570
pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
577-
self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get`
571+
self.as_local_hir_id(id).map(|id| self.get_by_hir_id(id)) // read recorded by `get`
578572
}
579573

580574
pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {

src/librustc_driver/pretty.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ pub fn print_after_hir_lowering<'tcx>(
830830
box out,
831831
annotation.pp_ann());
832832
for node_id in uii.all_matching_node_ids(hir_map) {
833-
let node = hir_map.get(node_id);
833+
let hir_id = tcx.hir().node_to_hir_id(node_id);
834+
let node = hir_map.get_by_hir_id(hir_id);
834835
pp_state.print_node(node)?;
835836
pp_state.s.space()?;
836837
let path = annotation.node_path(node_id)
@@ -847,7 +848,8 @@ pub fn print_after_hir_lowering<'tcx>(
847848
s.call_with_pp_support_hir(tcx, move |_annotation, _krate| {
848849
debug!("pretty printing source code {:?}", s);
849850
for node_id in uii.all_matching_node_ids(tcx.hir()) {
850-
let node = tcx.hir().get(node_id);
851+
let hir_id = tcx.hir().node_to_hir_id(node_id);
852+
let node = tcx.hir().get_by_hir_id(hir_id);
851853
write!(out, "{:#?}", node)?;
852854
}
853855
Ok(())

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
233233
}
234234

235235
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
236-
match self.save_ctxt.get_path_res(ref_id) {
236+
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ref_id);
237+
match self.save_ctxt.get_path_res(hir_id) {
237238
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
238239
def => Some(def.def_id()),
239240
}
@@ -886,7 +887,8 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
886887
return;
887888
}
888889
};
889-
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
890+
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(p.id);
891+
let variant = adt.variant_of_res(self.save_ctxt.get_path_res(hir_id));
890892

891893
for &Spanned { node: ref field, .. } in fields {
892894
if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
@@ -916,7 +918,8 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
916918

917919
// process collected paths
918920
for (id, ident, immut) in collector.collected_idents {
919-
match self.save_ctxt.get_path_res(id) {
921+
let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(id);
922+
match self.save_ctxt.get_path_res(hir_id) {
920923
Res::Local(hir_id) => {
921924
let mut value = if immut == ast::Mutability::Immutable {
922925
self.span.snippet(ident.span)
@@ -1540,8 +1543,7 @@ impl<'l, 'tcx, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tcx, '
15401543
return;
15411544
}
15421545
};
1543-
let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id);
1544-
let res = self.save_ctxt.get_path_res(node_id);
1546+
let res = self.save_ctxt.get_path_res(hir_expr.hir_id);
15451547
self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
15461548
}
15471549
ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args),

src/librustc_save_analysis/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
606606
}
607607
}
608608

609-
pub fn get_path_res(&self, id: NodeId) -> Res {
610-
match self.tcx.hir().get(id) {
609+
pub fn get_path_res(&self, hir_id: hir::HirId) -> Res {
610+
match self.tcx.hir().get_by_hir_id(hir_id) {
611611
Node::TraitRef(tr) => tr.path.res,
612612

613613
Node::Item(&hir::Item {
@@ -620,15 +620,14 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
620620
Node::PathSegment(seg) => {
621621
match seg.res {
622622
Some(res) if res != Res::Err => res,
623-
_ => self.get_path_res(self.tcx.hir().get_parent_node(id)),
623+
_ => self.get_path_res(self.tcx.hir().get_parent_node_by_hir_id(hir_id)),
624624
}
625625
}
626626

627627
Node::Expr(&hir::Expr {
628628
node: hir::ExprKind::Struct(ref qpath, ..),
629629
..
630630
}) => {
631-
let hir_id = self.tcx.hir().node_to_hir_id(id);
632631
self.tables.qpath_res(qpath, hir_id)
633632
}
634633

@@ -652,7 +651,6 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
652651
node: hir::TyKind::Path(ref qpath),
653652
..
654653
}) => {
655-
let hir_id = self.tcx.hir().node_to_hir_id(id);
656654
self.tables.qpath_res(qpath, hir_id)
657655
}
658656

@@ -697,7 +695,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
697695
return None;
698696
}
699697

700-
let res = self.get_path_res(id);
698+
let hir_id = self.tcx.hir().node_to_hir_id(id);
699+
let res = self.get_path_res(hir_id);
701700
let span = path_seg.ident.span;
702701
filter!(self.span_utils, span);
703702
let span = self.span_from_span(span);
@@ -869,7 +868,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
869868
}
870869

871870
fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> {
872-
match self.get_path_res(ref_id) {
871+
let hir_id = self.tcx.hir().node_to_hir_id(ref_id);
872+
match self.get_path_res(hir_id) {
873873
Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
874874
def => Some(def.def_id()),
875875
}

src/librustc_save_analysis/sig.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,8 @@ impl Sig for ast::Ty {
273273
};
274274

275275
let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?);
276-
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
276+
let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id));
277+
let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
277278
let id = id_from_def_id(res.def_id());
278279
if path.segments.len() - qself.position == 1 {
279280
let start = offset + prefix.len();
@@ -576,7 +577,8 @@ impl Sig for ast::Item {
576577

577578
impl Sig for ast::Path {
578579
fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result {
579-
let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
580+
let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id));
581+
let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
580582

581583
let (name, start, end) = match res {
582584
Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => {

0 commit comments

Comments
 (0)