]> git.lizzy.rs Git - rust.git/commitdiff
remove hir::map::get
authorljedrz <ljedrz@gmail.com>
Thu, 20 Jun 2019 08:34:57 +0000 (10:34 +0200)
committerljedrz <ljedrz@gmail.com>
Thu, 20 Jun 2019 10:47:26 +0000 (12:47 +0200)
src/librustc/hir/map/mod.rs
src/librustc_driver/pretty.rs
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/sig.rs

index 51ebd1188a52ba11861eb5750c982364d713cc73..0cd4c98ec6c8471e25cb80c3ac7622523caed9e3 100644 (file)
@@ -561,12 +561,6 @@ pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
     }
 
     /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found.
-    pub fn get(&self, id: NodeId) -> Node<'hir> {
-        let hir_id = self.node_to_hir_id(id);
-        self.get_by_hir_id(hir_id)
-    }
-
-    // FIXME(@ljedrz): replace the `NodeId` variant.
     pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> {
         // read recorded by `find`
         self.find_by_hir_id(id).unwrap_or_else(||
@@ -574,7 +568,7 @@ pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> {
     }
 
     pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
-        self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get`
+        self.as_local_hir_id(id).map(|id| self.get_by_hir_id(id)) // read recorded by `get`
     }
 
     pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
index 13f179f037ff3afea202a1ce8fdf69c9aa7d2464..7b2c70a3cad4a31c3a8e72a068585cfb7cc92e24 100644 (file)
@@ -830,7 +830,8 @@ pub fn print_after_hir_lowering<'tcx>(
                                                                          box out,
                                                                          annotation.pp_ann());
                     for node_id in uii.all_matching_node_ids(hir_map) {
-                        let node = hir_map.get(node_id);
+                        let hir_id = tcx.hir().node_to_hir_id(node_id);
+                        let node = hir_map.get_by_hir_id(hir_id);
                         pp_state.print_node(node)?;
                         pp_state.s.space()?;
                         let path = annotation.node_path(node_id)
@@ -847,7 +848,8 @@ pub fn print_after_hir_lowering<'tcx>(
                 s.call_with_pp_support_hir(tcx, move |_annotation, _krate| {
                     debug!("pretty printing source code {:?}", s);
                     for node_id in uii.all_matching_node_ids(tcx.hir()) {
-                        let node = tcx.hir().get(node_id);
+                        let hir_id = tcx.hir().node_to_hir_id(node_id);
+                        let node = tcx.hir().get_by_hir_id(hir_id);
                         write!(out, "{:#?}", node)?;
                     }
                     Ok(())
index f67241ef23efcbf6d6ca4d5246c62869c0d52d06..4719965da8d66975de92c7d193f8ba75b8a18275 100644 (file)
@@ -233,7 +233,8 @@ fn write_sub_paths_truncated(&mut self, path: &ast::Path) {
     }
 
     fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
-        match self.save_ctxt.get_path_res(ref_id) {
+        let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(ref_id);
+        match self.save_ctxt.get_path_res(hir_id) {
             Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => None,
             def => Some(def.def_id()),
         }
@@ -886,7 +887,8 @@ fn process_pat(&mut self, p: &'l ast::Pat) {
                         return;
                     }
                 };
-                let variant = adt.variant_of_res(self.save_ctxt.get_path_res(p.id));
+                let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(p.id);
+                let variant = adt.variant_of_res(self.save_ctxt.get_path_res(hir_id));
 
                 for &Spanned { node: ref field, .. } in fields {
                     if let Some(index) = self.tcx.find_field_index(field.ident, variant) {
@@ -916,7 +918,8 @@ fn process_var_decl_multi(&mut self, pats: &'l [P<ast::Pat>]) {
 
         // process collected paths
         for (id, ident, immut) in collector.collected_idents {
-            match self.save_ctxt.get_path_res(id) {
+            let hir_id = self.save_ctxt.tcx.hir().node_to_hir_id(id);
+            match self.save_ctxt.get_path_res(hir_id) {
                 Res::Local(hir_id) => {
                     let mut value = if immut == ast::Mutability::Immutable {
                         self.span.snippet(ident.span)
@@ -1540,8 +1543,7 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
                         return;
                     }
                 };
-                let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id);
-                let res = self.save_ctxt.get_path_res(node_id);
+                let res = self.save_ctxt.get_path_res(hir_expr.hir_id);
                 self.process_struct_lit(ex, path, fields, adt.variant_of_res(res), base)
             }
             ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args),
index 0664327d4031d77734d710a9d5852c419acf2551..231fbac1f95d5da05ee9c34ffec9184dea9c52b0 100644 (file)
@@ -606,8 +606,8 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
         }
     }
 
-    pub fn get_path_res(&self, id: NodeId) -> Res {
-        match self.tcx.hir().get(id) {
+    pub fn get_path_res(&self, hir_id: hir::HirId) -> Res {
+        match self.tcx.hir().get_by_hir_id(hir_id) {
             Node::TraitRef(tr) => tr.path.res,
 
             Node::Item(&hir::Item {
@@ -620,7 +620,7 @@ pub fn get_path_res(&self, id: NodeId) -> Res {
             Node::PathSegment(seg) => {
                 match seg.res {
                     Some(res) if res != Res::Err => res,
-                    _ => self.get_path_res(self.tcx.hir().get_parent_node(id)),
+                    _ => self.get_path_res(self.tcx.hir().get_parent_node_by_hir_id(hir_id)),
                 }
             }
 
@@ -628,7 +628,6 @@ pub fn get_path_res(&self, id: NodeId) -> Res {
                 node: hir::ExprKind::Struct(ref qpath, ..),
                 ..
             }) => {
-                let hir_id = self.tcx.hir().node_to_hir_id(id);
                 self.tables.qpath_res(qpath, hir_id)
             }
 
@@ -652,7 +651,6 @@ pub fn get_path_res(&self, id: NodeId) -> Res {
                 node: hir::TyKind::Path(ref qpath),
                 ..
             }) => {
-                let hir_id = self.tcx.hir().node_to_hir_id(id);
                 self.tables.qpath_res(qpath, hir_id)
             }
 
@@ -697,7 +695,8 @@ fn fn_type(seg: &ast::PathSegment) -> bool {
             return None;
         }
 
-        let res = self.get_path_res(id);
+        let hir_id = self.tcx.hir().node_to_hir_id(id);
+        let res = self.get_path_res(hir_id);
         let span = path_seg.ident.span;
         filter!(self.span_utils, span);
         let span = self.span_from_span(span);
@@ -869,7 +868,8 @@ pub fn get_macro_use_data(&self, span: Span) -> Option<MacroRef> {
     }
 
     fn lookup_ref_id(&self, ref_id: NodeId) -> Option<DefId> {
-        match self.get_path_res(ref_id) {
+        let hir_id = self.tcx.hir().node_to_hir_id(ref_id);
+        match self.get_path_res(hir_id) {
             Res::PrimTy(_) | Res::SelfTy(..) | Res::Err => None,
             def => Some(def.def_id()),
         }
index db8b5eacd94d9321f2f7e7b9b1175f927590e693..7af18a8676abb9c7eef8e5905e01b47cb6c74bc9 100644 (file)
@@ -273,7 +273,8 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext<'_,
                 };
 
                 let name = pprust::path_segment_to_string(path.segments.last().ok_or("Bad path")?);
-                let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
+                let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id));
+                let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
                 let id = id_from_def_id(res.def_id());
                 if path.segments.len() - qself.position == 1 {
                     let start = offset + prefix.len();
@@ -576,7 +577,8 @@ fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext<'_,
 
 impl Sig for ast::Path {
     fn make(&self, offset: usize, id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result {
-        let res = scx.get_path_res(id.ok_or("Missing id for Path")?);
+        let hir_id = id.map(|node_id| scx.tcx.hir().node_to_hir_id(node_id));
+        let res = scx.get_path_res(hir_id.ok_or("Missing id for Path")?);
 
         let (name, start, end) = match res {
             Res::PrimTy(..) | Res::SelfTy(..) | Res::Err => {