]> git.lizzy.rs Git - rust.git/commitdiff
HIR: remove the NodeId find
authorljedrz <ljedrz@gmail.com>
Mon, 24 Jun 2019 07:55:11 +0000 (09:55 +0200)
committerljedrz <ljedrz@gmail.com>
Mon, 24 Jun 2019 07:55:11 +0000 (09:55 +0200)
src/librustc/hir/map/mod.rs
src/librustc_driver/pretty.rs
src/librustc_mir/build/mod.rs
src/librustc_save_analysis/lib.rs

index bb39f85e1c3bd21d51a3d4b82c04704f5fd0cd20..ea18a73577cf069fc975cf5991c962d8f8b42acf 100644 (file)
@@ -595,12 +595,6 @@ pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> {
     }
 
     /// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
-    pub fn find(&self, id: NodeId) -> Option<Node<'hir>> {
-        let hir_id = self.node_to_hir_id(id);
-        self.find_by_hir_id(hir_id)
-    }
-
-    // FIXME(@ljedrz): replace the `NodeId` variant.
     pub fn find_by_hir_id(&self, hir_id: HirId) -> Option<Node<'hir>> {
         let result = self.find_entry(hir_id).and_then(|entry| {
             if let Node::Crate = entry.node {
index 1b78f77e4f915d09bfbb150b2c19d0e45f5cb5ec..ff0e6aacef138061bf1ba87f9d4d84208e9ebce3 100644 (file)
@@ -907,11 +907,11 @@ fn print_with_analysis<'tcx>(
             let nodeid =
                 nodeid.expect("`pretty flowgraph=..` needs NodeId (int) or unique path \
                                 suffix (b::c::d)");
-            let node = tcx.hir().find(nodeid).unwrap_or_else(|| {
+            let hir_id = tcx.hir().node_to_hir_id(nodeid);
+            let node = tcx.hir().find_by_hir_id(hir_id).unwrap_or_else(|| {
                 tcx.sess.fatal(&format!("--pretty flowgraph couldn't find id: {}", nodeid))
             });
 
-            let hir_id = tcx.hir().node_to_hir_id(nodeid);
             match blocks::Code::from_node(&tcx.hir(), hir_id) {
                 Some(code) => {
                     let variants = gather_flowgraph_variants(tcx.sess);
index 66064221b391c4b9b162359ec71e8d9007f39383..1cc15ca484eca1b47c7053d8ce98021cd1651e00 100644 (file)
@@ -552,7 +552,6 @@ fn construct_fn<'a, 'tcx, A>(
         .into_iter()
         .flatten()
         .map(|(&var_hir_id, &upvar_id)| {
-            let var_node_id = tcx_hir.hir_to_node_id(var_hir_id);
             let capture = hir_tables.upvar_capture(upvar_id);
             let by_ref = match capture {
                 ty::UpvarCapture::ByValue => false,
@@ -563,7 +562,7 @@ fn construct_fn<'a, 'tcx, A>(
                 by_ref,
             };
             let mut mutability = Mutability::Not;
-            if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) {
+            if let Some(Node::Binding(pat)) = tcx_hir.find_by_hir_id(var_hir_id) {
                 if let hir::PatKind::Binding(_, _, ident, _) = pat.node {
                     debuginfo.debug_name = ident.name;
                     if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
index 750222451db6f5637e35c3d55aac5ff249aaab8e..3d88b2347c17a3ed02b67e59fd62d8ed82dfd755 100644 (file)
@@ -410,7 +410,10 @@ pub fn get_method_data(&self, id: ast::NodeId, ident: ast::Ident, span: Span) ->
                             let mut decl_id = None;
                             let mut docs = String::new();
                             let mut attrs = vec![];
-                            if let Some(Node::ImplItem(item)) = self.tcx.hir().find(id) {
+                            let hir_id = self.tcx.hir().node_to_hir_id(id);
+                            if let Some(Node::ImplItem(item)) =
+                                self.tcx.hir().find_by_hir_id(hir_id)
+                            {
                                 docs = self.docs_for_attrs(&item.attrs);
                                 attrs = item.attrs.to_vec();
                             }
@@ -451,8 +454,9 @@ pub fn get_method_data(&self, id: ast::NodeId, ident: ast::Ident, span: Span) ->
                     Some(def_id) => {
                         let mut docs = String::new();
                         let mut attrs = vec![];
+                        let hir_id = self.tcx.hir().node_to_hir_id(id);
 
-                        if let Some(Node::TraitItem(item)) = self.tcx.hir().find(id) {
+                        if let Some(Node::TraitItem(item)) = self.tcx.hir().find_by_hir_id(hir_id) {
                             docs = self.docs_for_attrs(&item.attrs);
                             attrs = item.attrs.to_vec();
                         }
@@ -521,7 +525,8 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
         }
         match expr.node {
             ast::ExprKind::Field(ref sub_ex, ident) => {
-                let hir_node = match self.tcx.hir().find(sub_ex.id) {
+                let sub_ex_hir_id = self.tcx.hir().node_to_hir_id(sub_ex.id);
+                let hir_node = match self.tcx.hir().find_by_hir_id(sub_ex_hir_id) {
                     Some(Node::Expr(expr)) => expr,
                     _ => {
                         debug!(