]> git.lizzy.rs Git - rust.git/commitdiff
scrap `find_node_for_hir_id` in favor of `hir_to_node_id`
authorZack M. Davis <code@zackmdavis.net>
Sun, 27 May 2018 00:30:26 +0000 (17:30 -0700)
committerZack M. Davis <code@zackmdavis.net>
Mon, 28 May 2018 16:20:14 +0000 (09:20 -0700)
Michael Woerister pointed out that `hir_to_node_id` (introduced in
August 2017's 28ddd7a4e) supersedes the functionality of
`find_node_for_hir_id` (just a hash lookup compared to that linear
search).

src/librustc/hir/map/definitions.rs
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/mem_categorization.rs
src/librustc/ty/context.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/writeback.rs
src/librustc_typeck/check_unused.rs

index e380a7bfbfebe33ba38244611b910ffa7d91e391..838be076a0b62c397ec9be7ad8bc2fc2dc57c2dd 100644 (file)
@@ -487,14 +487,6 @@ pub fn node_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
         self.node_to_hir_id[node_id]
     }
 
-    pub fn find_node_for_hir_id(&self, hir_id: hir::HirId) -> ast::NodeId {
-        self.node_to_hir_id
-            .iter()
-            .position(|x| *x == hir_id)
-            .map(|idx| ast::NodeId::new(idx))
-            .unwrap()
-    }
-
     #[inline]
     pub fn def_index_to_hir_id(&self, def_index: DefIndex) -> hir::HirId {
         let space_index = def_index.address_space().index();
index 66c6cf73513ec921d4cfe36e604b1740b8ca454c..ddbc03292f6442501a65c89d3d947d16472dcab3 100644 (file)
@@ -609,8 +609,7 @@ fn walk_local(&mut self, local: &hir::Local) {
         match local.init {
             None => {
                 local.pat.each_binding(|_, hir_id, span, _| {
-                    // FIXME: converting HirId → NodeId is said to be relatively expensive
-                    let node_id = self.mc.tcx.hir.definitions().find_node_for_hir_id(hir_id);
+                    let node_id = self.mc.tcx.hir.hir_to_node_id(hir_id);
                     self.delegate.decl_without_init(node_id, span);
                 })
             }
index 39c4da08b03a39c7ea0a3b5f62e80a62dfccc783..37732708733b040cf578b6c430f26bfe81d18907 100644 (file)
@@ -488,7 +488,7 @@ fn resolve_type_vars_or_error(&self,
             // FIXME
             None if self.is_tainted_by_errors() => Err(()),
             None => {
-                let id = self.tcx.hir.definitions().find_node_for_hir_id(id);
+                let id = self.tcx.hir.hir_to_node_id(id);
                 bug!("no type for node {}: {} in mem_categorization",
                      id, self.tcx.hir.node_to_string(id));
             }
index df2996d7ee1f55f6a9529764107697102c912886..9d3dda46dade1c997fd312581f23b8c18bed693c 100644 (file)
@@ -266,9 +266,7 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
         if let Some(local_id_root) = local_id_root {
             if hir_id.owner != local_id_root.index {
                 ty::tls::with(|tcx| {
-                    let node_id = tcx.hir
-                                     .definitions()
-                                     .find_node_for_hir_id(hir_id);
+                    let node_id = tcx.hir.hir_to_node_id(hir_id);
 
                     bug!("node {} with HirId::owner {:?} cannot be placed in \
                           TypeckTables with local_id_root {:?}",
@@ -527,7 +525,7 @@ pub fn node_id_to_type(&self, id: hir::HirId) -> Ty<'tcx> {
             None => {
                 bug!("node_id_to_type: no type for node `{}`",
                     tls::with(|tcx| {
-                        let id = tcx.hir.definitions().find_node_for_hir_id(id);
+                        let id = tcx.hir.hir_to_node_id(id);
                         tcx.hir.node_to_string(id)
                     }))
             }
@@ -2616,8 +2614,7 @@ pub fn struct_span_lint_hir<S: Into<MultiSpan>>(self,
                                                     msg: &str)
         -> DiagnosticBuilder<'tcx>
     {
-        // FIXME: converting HirId → NodeId is said to be relatively expensive
-        let node_id = self.hir.definitions().find_node_for_hir_id(hir_id);
+        let node_id = self.hir.hir_to_node_id(hir_id);
         let (level, src) = self.lint_level_at_node(lint, node_id);
         lint::struct_lint_level(self.sess, lint, level, src, Some(span.into()), msg)
     }
index 9452d2332cf4a405941764ef4a8ae2efbf010895..90b974fb972c00534312bd06f6b19e8adca0eafd 100644 (file)
@@ -2110,7 +2110,7 @@ pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> {
             Some(&t) => t,
             None if self.is_tainted_by_errors() => self.tcx.types.err,
             None => {
-                let node_id = self.tcx.hir.definitions().find_node_for_hir_id(id);
+                let node_id = self.tcx.hir.hir_to_node_id(id);
                 bug!("no type for node {}: {} in fcx {}",
                      node_id, self.tcx.hir.node_to_string(node_id),
                      self.tag());
index b0ee1154e863b37999a2f8626341a9454c6fc515..f295d1763c4c75c5c3ac575ea7022f411f0c6c18 100644 (file)
@@ -560,7 +560,7 @@ fn to_span(&self, tcx: &TyCtxt) -> Span {
 
 impl Locatable for hir::HirId {
     fn to_span(&self, tcx: &TyCtxt) -> Span {
-        let node_id = tcx.hir.definitions().find_node_for_hir_id(*self);
+        let node_id = tcx.hir.hir_to_node_id(*self);
         tcx.hir.span(node_id)
     }
 }
index f2f1e2938cb1283f65b4de5e3513d0197b92a0cd..bff849d7ae8e99d2a8cd83138442c588c6c4dd24 100644 (file)
@@ -106,7 +106,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
         }
         assert_eq!(def_id.krate, LOCAL_CRATE);
         let hir_id = tcx.hir.definitions().def_index_to_hir_id(def_id.index);
-        let id = tcx.hir.definitions().find_node_for_hir_id(hir_id);
+        let id = tcx.hir.hir_to_node_id(hir_id);
         let lint = lint::builtin::UNUSED_EXTERN_CRATES;
         let msg = "unused extern crate";
         tcx.lint_node(lint, id, span, msg);