From 61964d9732847a3c208c48d07cb8c2ddae8ddb3c Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 14 Jun 2019 12:28:47 +0200 Subject: [PATCH 1/8] replace some uses of NodeId with HirId --- src/librustc/cfg/construct.rs | 3 +- src/librustc/cfg/graphviz.rs | 6 +- src/librustc/hir/map/hir_id_validator.rs | 3 +- src/librustc/hir/map/mod.rs | 98 ++----------------- src/librustc/hir/upvars.rs | 4 +- src/librustc/infer/error_reporting/mod.rs | 8 +- .../nice_region_error/find_anon_type.rs | 4 +- .../nice_region_error/outlives_closure.rs | 4 +- .../error_reporting/nice_region_error/util.rs | 8 +- src/librustc/middle/mem_categorization.rs | 21 ++-- src/librustc/middle/region.rs | 19 ++-- src/librustc/middle/resolve_lifetime.rs | 4 +- src/librustc/traits/error_reporting.rs | 6 +- src/librustc/ty/context.rs | 4 +- src/librustc_borrowck/borrowck/mod.rs | 19 ++-- src/librustc_driver/pretty.rs | 3 +- .../borrow_check/mutability_errors.rs | 4 +- .../error_reporting/region_name.rs | 20 ++-- src/librustc_mir/build/mod.rs | 6 +- src/librustc_mir/hair/cx/expr.rs | 11 ++- src/librustc_mir/interpret/validity.rs | 4 +- src/librustc_passes/rvalue_promotion.rs | 4 +- src/librustc_typeck/astconv.rs | 10 +- src/librustc_typeck/check/mod.rs | 3 +- src/librustc_typeck/check/writeback.rs | 7 +- src/librustc_typeck/collect.rs | 2 +- 26 files changed, 95 insertions(+), 190 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 139c144fbcf4e..8eea01cc4acca 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -42,7 +42,8 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG { let body_exit; // Find the tables for this body. - let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id())); + let owner_hir_id = tcx.hir().body_owner(body.id()); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_hir_id); let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index dbc462ee49b37..0bfb6b98e630b 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> { impl<'a, 'tcx> LabelledCFG<'a, 'tcx> { fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String { assert!(self.cfg.owner_def_id.is_local()); - let node_id = self.tcx.hir().hir_to_node_id(hir::HirId { + let hir_id = hir::HirId { owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner, local_id - }); - let s = self.tcx.hir().node_to_string(node_id); + }; + let s = self.tcx.hir().hir_to_string(hir_id); // Replacing newlines with \\l causes each line to be left-aligned, // improving presentation of (long) pretty-printed expressions. diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index fafe671b9eb8b..08ec2aeed2905 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -122,9 +122,10 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { .find(|&(_, &entry)| hir_id == entry) .expect("no node_to_hir_id entry"); let node_id = NodeId::from_usize(node_id); + let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, - self.hir_map.node_to_string(node_id))); + self.hir_map.hir_to_string(hir_id))); } self.error(|| format!( "ItemLocalIds not assigned densely in {}. \ diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 978a5556d31bf..680fe2866bcea 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -286,21 +286,11 @@ impl<'hir> Map<'hir> { self.definitions.def_index_to_hir_id(def_index) } - #[inline] - pub fn def_index_to_node_id(&self, def_index: DefIndex) -> NodeId { - self.definitions.def_index_to_node_id(def_index) - } - #[inline] pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId { self.definitions.def_index_to_hir_id(def_id.to_def_id().index) } - #[inline] - pub fn local_def_id_to_node_id(&self, def_id: LocalDefId) -> NodeId { - self.definitions.as_local_node_id(def_id.to_def_id()).unwrap() - } - fn def_kind(&self, node_id: NodeId) -> Option { let node = if let Some(node) = self.find(node_id) { node @@ -422,12 +412,6 @@ impl<'hir> Map<'hir> { self.forest.krate.body(id) } - pub fn fn_decl(&self, node_id: ast::NodeId) -> Option { - let hir_id = self.node_to_hir_id(node_id); - self.fn_decl_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn fn_decl_by_hir_id(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { entry.fn_decl().cloned() @@ -439,24 +423,18 @@ impl<'hir> Map<'hir> { /// Returns the `NodeId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. - pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId { + pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.get_parent_node_by_hir_id(hir_id); assert!(self.lookup(parent).map_or(false, |e| e.is_body_owner(hir_id))); - self.hir_to_node_id(parent) + parent } pub fn body_owner_def_id(&self, id: BodyId) -> DefId { - self.local_def_id(self.body_owner(id)) + self.local_def_id_from_hir_id(self.body_owner(id)) } - /// Given a `NodeId`, returns the `BodyId` associated with it, + /// Given a `HirId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. - pub fn maybe_body_owned_by(&self, id: NodeId) -> Option { - let hir_id = self.node_to_hir_id(id); - self.maybe_body_owned_by_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { if self.dep_graph.is_fully_enabled() { @@ -479,12 +457,6 @@ impl<'hir> Map<'hir> { }) } - pub fn body_owner_kind(&self, id: NodeId) -> BodyOwnerKind { - let hir_id = self.node_to_hir_id(id); - self.body_owner_kind_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind { match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | @@ -793,17 +765,10 @@ impl<'hir> Map<'hir> { self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok() } - /// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no + /// Retrieves the `HirId` for `id`'s parent item, or `id` itself if no /// parent item is in this map. The "parent item" is the closest parent node /// in the HIR which is recorded by the map and is an item, either an item /// in a module, trait, or impl. - pub fn get_parent(&self, id: NodeId) -> NodeId { - let hir_id = self.node_to_hir_id(id); - let parent_hir_id = self.get_parent_item(hir_id); - self.hir_to_node_id(parent_hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_parent_item(&self, hir_id: HirId) -> HirId { match self.walk_parent_nodes(hir_id, |node| match *node { Node::Item(_) | @@ -819,12 +784,6 @@ impl<'hir> Map<'hir> { /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent(&self, id: NodeId) -> DefId { - let hir_id = self.node_to_hir_id(id); - self.get_module_parent_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_module_parent_node(id)) } @@ -901,22 +860,10 @@ impl<'hir> Map<'hir> { Some(scope) } - pub fn get_parent_did(&self, id: NodeId) -> DefId { - let hir_id = self.node_to_hir_id(id); - self.get_parent_did_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_parent_item(id)) } - pub fn get_foreign_abi(&self, id: NodeId) -> Abi { - let hir_id = self.node_to_hir_id(id); - self.get_foreign_abi_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi { let parent = self.get_parent_item(hir_id); if let Some(entry) = self.find_entry(parent) { @@ -930,12 +877,6 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) } - pub fn expect_item(&self, id: NodeId) -> &'hir Item { - let hir_id = self.node_to_hir_id(id); - self.expect_item_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, @@ -1024,12 +965,6 @@ impl<'hir> Map<'hir> { /// Given a node ID, gets a list of attributes associated with the AST /// corresponding to the node-ID. - pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] { - let hir_id = self.node_to_hir_id(id); - self.attrs_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find_entry(id).map(|entry| entry.node) { @@ -1093,12 +1028,6 @@ impl<'hir> Map<'hir> { }) } - pub fn span(&self, id: NodeId) -> Span { - let hir_id = self.node_to_hir_id(id); - self.span_by_hir_id(hir_id) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn span_by_hir_id(&self, hir_id: HirId) -> Span { self.read(hir_id); // reveals span from node match self.find_entry(hir_id).map(|entry| entry.node) { @@ -1139,32 +1068,17 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - self.as_local_node_id(id).map(|id| self.span(id)) + self.as_local_hir_id(id).map(|id| self.span_by_hir_id(id)) } - pub fn node_to_string(&self, id: NodeId) -> String { - hir_id_to_string(self, self.node_to_hir_id(id), true) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_string(&self, id: HirId) -> String { hir_id_to_string(self, id, true) } - pub fn node_to_user_string(&self, id: NodeId) -> String { - hir_id_to_string(self, self.node_to_hir_id(id), false) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_user_string(&self, id: HirId) -> String { hir_id_to_string(self, id, false) } - pub fn node_to_pretty_string(&self, id: NodeId) -> String { - print::to_string(self, |s| s.print_node(self.get(id))) - } - - // FIXME(@ljedrz): replace the `NodeId` variant. pub fn hir_to_pretty_string(&self, id: HirId) -> String { print::to_string(self, |s| s.print_node(self.get_by_hir_id(id))) } diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index 1a4fe35c530bb..662bde43c569c 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -14,8 +14,8 @@ pub fn provide(providers: &mut Providers<'_>) { return None; } - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(node_id)?); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)?); let mut local_collector = LocalCollector::default(); local_collector.visit_body(body); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 04d29a8db1c35..73bd37d53fe28 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -86,7 +86,7 @@ impl<'tcx> TyCtxt<'tcx> { ) }; let span = scope.span(self, region_scope_tree); - let tag = match self.hir().find(scope.node_id(self, region_scope_tree)) { + let tag = match self.hir().find_by_hir_id(scope.hir_id(region_scope_tree)) { Some(Node::Block(_)) => "block", Some(Node::Expr(expr)) => match expr.node { hir::ExprKind::Call(..) => "call", @@ -1330,15 +1330,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if !param.is_self() { let type_param = generics.type_param(param, self.tcx); let hir = &self.tcx.hir(); - hir.as_local_node_id(type_param.def_id).map(|id| { + hir.as_local_hir_id(type_param.def_id).map(|id| { // Get the `hir::Param` to verify whether it already has any bounds. // We do this to avoid suggesting code that ends up as `T: 'a'b`, // instead we suggest `T: 'a + 'b` in that case. let mut has_bounds = false; - if let Node::GenericParam(ref param) = hir.get(id) { + if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { has_bounds = !param.bounds.is_empty(); } - let sp = hir.span(id); + let sp = hir.span_by_hir_id(id); // `sp` only covers `T`, change it so that it covers // `T:` when appropriate let is_impl_trait = bound_kind.to_string().starts_with("impl "); diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index fa95ea1013253..78d1d56993e06 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -28,8 +28,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { ) -> Option<(&hir::Ty, &hir::FnDecl)> { if let Some(anon_reg) = self.tcx().is_suitable_region(region) { let def_id = anon_reg.def_id; - if let Some(node_id) = self.tcx().hir().as_local_node_id(def_id) { - let fndecl = match self.tcx().hir().get(node_id) { + if let Some(hir_id) = self.tcx().hir().as_local_hir_id(def_id) { + let fndecl = match self.tcx().hir().get_by_hir_id(hir_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(ref fndecl, ..), .. diff --git a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs index 0d98a024977d9..6ed2b67556ddc 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/outlives_closure.rs @@ -48,11 +48,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { if let (&SubregionOrigin::BindingTypeIsNotValidAtDecl(ref external_span), &RegionKind::ReFree(ref free_region)) = (&sub_origin, sup_region) { let hir = &self.tcx().hir(); - if let Some(node_id) = hir.as_local_node_id(free_region.scope) { + if let Some(hir_id) = hir.as_local_hir_id(free_region.scope) { if let Node::Expr(Expr { node: Closure(_, _, _, closure_span, None), .. - }) = hir.get(node_id) { + }) = hir.get_by_hir_id(hir_id) { let sup_sp = sup_origin.span(); let origin_sp = origin.span(); let mut err = self.tcx().sess.struct_span_err( diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 017f36b020988..061d74416c57f 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -51,11 +51,11 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { }; let hir = &self.tcx().hir(); - if let Some(node_id) = hir.as_local_node_id(id) { - if let Some(body_id) = hir.maybe_body_owned_by(node_id) { + if let Some(hir_id) = hir.as_local_hir_id(id) { + if let Some(body_id) = hir.maybe_body_owned_by_by_hir_id(hir_id) { let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); - let fn_decl = hir.fn_decl(owner_id).unwrap(); + let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); if let Some(tables) = self.tables { body.arguments .iter() @@ -63,7 +63,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { .filter_map(|(index, arg)| { // May return None; sometimes the tables are not yet populated. let ty_hir_id = fn_decl.inputs[index].hir_id; - let arg_ty_span = hir.span(hir.hir_to_node_id(ty_hir_id)); + let arg_ty_span = hir.span_by_hir_id(ty_hir_id); let ty = tables.node_type_opt(arg.hir_id)?; let mut found_anon_region = false; let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3b21b81df7b43..cf304ebf3cbf4 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -342,9 +342,9 @@ impl MutabilityCategory { fn from_local( tcx: TyCtxt<'_>, tables: &ty::TypeckTables<'_>, - id: ast::NodeId, + id: hir::HirId, ) -> MutabilityCategory { - let ret = match tcx.hir().get(id) { + let ret = match tcx.hir().get_by_hir_id(id) { Node::Binding(p) => match p.node { PatKind::Binding(..) => { let bm = *tables.pat_binding_modes() @@ -358,7 +358,7 @@ impl MutabilityCategory { } _ => span_bug!(p.span, "expected identifier pattern") }, - _ => span_bug!(tcx.hir().span(id), "expected identifier pattern") + _ => span_bug!(tcx.hir().span_by_hir_id(id), "expected identifier pattern") }; debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}", "from_local", id, ret); @@ -500,9 +500,8 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { // FIXME None if self.is_tainted_by_errors() => Err(()), None => { - 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)); + id, self.tcx.hir().hir_to_string(id)); } } } @@ -753,15 +752,14 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } Res::Local(var_id) => { - let var_nid = self.tcx.hir().hir_to_node_id(var_id); if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) { - self.cat_upvar(hir_id, span, var_nid) + self.cat_upvar(hir_id, span, var_id) } else { Ok(cmt_ { hir_id, span, cat: Categorization::Local(var_id), - mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_nid), + mutbl: MutabilityCategory::from_local(self.tcx, self.tables, var_id), ty: expr_ty, note: NoteNone }) @@ -778,7 +776,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { &self, hir_id: hir::HirId, span: Span, - var_id: ast::NodeId, + var_id: hir::HirId, ) -> McResult> { // An upvar can have up to 3 components. We translate first to a // `Categorization::Upvar`, which is itself a fiction -- it represents the reference to the @@ -828,13 +826,12 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { _ => span_bug!(span, "unexpected type for fn in mem_categorization: {:?}", ty), }; - let var_hir_id = self.tcx.hir().node_to_hir_id(var_id); let upvar_id = ty::UpvarId { - var_path: ty::UpvarPath { hir_id: var_hir_id }, + var_path: ty::UpvarPath { hir_id: var_id }, closure_expr_id: closure_expr_def_id.to_local(), }; - let var_ty = self.node_ty(var_hir_id)?; + let var_ty = self.node_ty(var_id)?; // Mutability of original variable itself let var_mutbl = MutabilityCategory::from_local(self.tcx, self.tables, var_id); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 8b1eeeb7f51b7..708bd6f735d89 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -14,7 +14,6 @@ use std::mem; use std::fmt; use rustc_macros::HashStable; use syntax::source_map; -use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; use crate::ty::{DefIdTree, TyCtxt}; use crate::ty::query::Providers; @@ -169,15 +168,15 @@ impl Scope { self.id } - pub fn node_id(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> ast::NodeId { + pub fn hir_id(&self, scope_tree: &ScopeTree) -> hir::HirId { match scope_tree.root_body { Some(hir_id) => { - tcx.hir().hir_to_node_id(hir::HirId { + hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() - }) + } } - None => ast::DUMMY_NODE_ID + None => hir::DUMMY_HIR_ID } } @@ -185,13 +184,13 @@ impl Scope { /// returned span may not correspond to the span of any `NodeId` in /// the AST. pub fn span(&self, tcx: TyCtxt<'_>, scope_tree: &ScopeTree) -> Span { - let node_id = self.node_id(tcx, scope_tree); - if node_id == ast::DUMMY_NODE_ID { + let hir_id = self.hir_id(scope_tree); + if hir_id == hir::DUMMY_HIR_ID { return DUMMY_SP; } - let span = tcx.hir().span(node_id); + let span = tcx.hir().span_by_hir_id(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { - if let Node::Block(ref blk) = tcx.hir().get(node_id) { + if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { // Want span for scope starting after the // indexed statement and ending at end of // `blk`; reuse span of `blk` and shift `lo` @@ -1278,7 +1277,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The body of the every fn is a root scope. self.cx.parent = self.cx.var_parent; - if self.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() { + if self.tcx.hir().body_owner_kind_by_hir_id(owner_id).is_fn_or_closure() { self.visit_expr(&body.value) } else { // Only functions have an outer terminating (drop) scope, while diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 48d2a477a9af4..b350f15664d44 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -1823,7 +1823,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Do not free early-bound regions, only late-bound ones. } else if let Some(body_id) = outermost_body { let fn_id = self.tcx.hir().body_owner(body_id); - match self.tcx.hir().get(fn_id) { + match self.tcx.hir().get_by_hir_id(fn_id) { Node::Item(&hir::Item { node: hir::ItemKind::Fn(..), .. @@ -1836,7 +1836,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { node: hir::ImplItemKind::Method(..), .. }) => { - let scope = self.tcx.hir().local_def_id(fn_id); + let scope = self.tcx.hir().local_def_id_from_hir_id(fn_id); def = Region::Free(scope, def.id().unwrap()); } _ => {} diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 42bde3563492f..f886794be6282 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1013,10 +1013,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { trait_ref: &ty::Binder>, ) { let hir = self.tcx.hir(); - let parent_node = hir.get_parent_node( - hir.hir_to_node_id(obligation.cause.body_id), - ); - let node = hir.find(parent_node); + let parent_node = hir.get_parent_node_by_hir_id(obligation.cause.body_id); + let node = hir.find_by_hir_id(parent_node); if let Some(hir::Node::Item(hir::Item { node: hir::ItemKind::Fn(decl, _, _, body_id), .. diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index e5d06532b3a16..c32f62e88c423 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -250,11 +250,9 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option, 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().hir_to_node_id(hir_id); - bug!("node {} with HirId::owner {:?} cannot be placed in \ TypeckTables with local_id_root {:?}", - tcx.hir().node_to_string(node_id), + tcx.hir().hir_to_string(hir_id), DefId::local(hir_id.owner), local_id_root) }); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 9b0dce50dd0cb..9429fde279086 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -198,7 +198,7 @@ pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( cfg: &cfg::CFG, ) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'tcx>) { let owner_id = tcx.hir().body_owner(body_id); - let owner_def_id = tcx.hir().local_def_id(owner_id); + let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_id); let tables = tcx.typeck_tables_of(owner_def_id); let region_scope_tree = tcx.region_scope_tree(owner_def_id); let body = tcx.hir().body(body_id); @@ -389,8 +389,8 @@ pub enum LoanPathElem<'tcx> { } fn closure_to_block(closure_id: LocalDefId, tcx: TyCtxt<'_>) -> HirId { - let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); - match tcx.hir().get(closure_id) { + let closure_id = tcx.hir().local_def_id_to_hir_id(closure_id); + match tcx.hir().get_by_hir_id(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { body_id.hir_id @@ -896,8 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node_id = self.tcx.hir().hir_to_node_id(err.cmt.hir_id); - let node = self.tcx.hir().get(node_id); + let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr( @@ -1022,8 +1021,8 @@ impl BorrowckCtxt<'_, 'tcx> { } if let ty::ReScope(scope) = *super_scope { - let node_id = scope.node_id(self.tcx, &self.region_scope_tree); - match self.tcx.hir().find(node_id) { + let hir_id = scope.hir_id(&self.region_scope_tree); + match self.tcx.hir().find_by_hir_id(hir_id) { Some(Node::Stmt(_)) => { if *sub_scope != ty::ReStatic { db.note("consider using a `let` binding to increase its lifetime"); @@ -1514,8 +1513,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(var_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(var_id) }); write!(f, "$({} captured by id={:?})", s, closure_expr_id) } @@ -1549,8 +1547,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => { let s = ty::tls::with(|tcx| { - let var_node_id = tcx.hir().hir_to_node_id(hir_id); - tcx.hir().node_to_string(var_node_id) + tcx.hir().hir_to_string(hir_id) }); write!(f, "$({} captured by closure)", s) } diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index e70c510b779c1..ef416dbe62b8e 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -922,7 +922,8 @@ fn print_with_analysis<'tcx>( got {:?}", node); - tcx.sess.span_fatal(tcx.hir().span(nodeid), &message) + let hir_id = tcx.hir().node_to_hir_id(nodeid); + tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &message) } } } diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index d3c23cfd65a66..fc11cd82f8a9a 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -304,8 +304,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_label(span, format!("cannot {ACT}", ACT = act)); let upvar_hir_id = self.upvars[upvar_index.index()].var_hir_id; - let upvar_node_id = self.infcx.tcx.hir().hir_to_node_id(upvar_hir_id); - if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find(upvar_node_id) { + if let Some(Node::Binding(pat)) = self.infcx.tcx.hir().find_by_hir_id(upvar_hir_id) + { if let hir::PatKind::Binding( hir::BindingAnnotation::Unannotated, _, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 1ec30897e92da..61a13df47ffe6 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -230,14 +230,14 @@ impl<'tcx> RegionInferenceContext<'tcx> { }, ty::BoundRegion::BrEnv => { - let mir_node_id = tcx.hir() - .as_local_node_id(mir_def_id) - .expect("non-local mir"); + let mir_hir_id = tcx.hir() + .as_local_hir_id(mir_def_id) + .expect("non-local mir"); let def_ty = self.universal_regions.defining_ty; if let DefiningTy::Closure(def_id, substs) = def_ty { let args_span = if let hir::ExprKind::Closure(_, _, _, span, _) = - tcx.hir().expect_expr(mir_node_id).node + tcx.hir().expect_expr_by_hir_id(mir_hir_id).node { span } else { @@ -367,8 +367,8 @@ impl<'tcx> RegionInferenceContext<'tcx> { argument_index: usize, counter: &mut usize, ) -> Option { - let mir_node_id = infcx.tcx.hir().as_local_node_id(mir_def_id)?; - let fn_decl = infcx.tcx.hir().fn_decl(mir_node_id)?; + let mir_hir_id = infcx.tcx.hir().as_local_hir_id(mir_def_id)?; + let fn_decl = infcx.tcx.hir().fn_decl_by_hir_id(mir_hir_id)?; let argument_hir_ty: &hir::Ty = &fn_decl.inputs[argument_index]; match argument_hir_ty.node { // This indicates a variable with no type annotation, like @@ -696,9 +696,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { highlight.highlighting_region_vid(fr, *counter); let type_name = infcx.extract_type_name(&return_ty, Some(highlight)); - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir"); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let (return_span, mir_description) = match tcx.hir().get(mir_node_id) { + let (return_span, mir_description) = match tcx.hir().get_by_hir_id(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, return_ty, _, span, gen_move), .. @@ -759,9 +759,9 @@ impl<'tcx> RegionInferenceContext<'tcx> { highlight.highlighting_region_vid(fr, *counter); let type_name = infcx.extract_type_name(&yield_ty, Some(highlight)); - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).expect("non-local mir"); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).expect("non-local mir"); - let yield_span = match tcx.hir().get(mir_node_id) { + let yield_span = match tcx.hir().get_by_hir_id(mir_hir_id) { hir::Node::Expr(hir::Expr { node: hir::ExprKind::Closure(_, _, _, span, _), .. diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 3a48f35ad0fe2..280592e2b0164 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -101,7 +101,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { let owner_id = tcx.hir().body_owner(body_id); let opt_ty_info; let self_arg; - if let Some(ref fn_decl) = tcx.hir().fn_decl(owner_id) { + if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); opt_ty_info = Some(ty_span); @@ -650,7 +650,7 @@ fn construct_const<'a, 'tcx>( ) -> Body<'tcx> { let tcx = hir.tcx(); let owner_id = tcx.hir().body_owner(body_id); - let span = tcx.hir().span(owner_id); + let span = tcx.hir().span_by_hir_id(owner_id); let mut builder = Builder::new( hir, span, @@ -689,7 +689,7 @@ fn construct_error<'a, 'tcx>( body_id: hir::BodyId ) -> Body<'tcx> { let owner_id = hir.tcx().hir().body_owner(body_id); - let span = hir.tcx().hir().span(owner_id); + let span = hir.tcx().hir().span_by_hir_id(owner_id); let ty = hir.tcx().types.err; let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![], false); let source_info = builder.source_info(span); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 89452b23880c0..9f05cf981f517 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -908,12 +908,13 @@ fn convert_path_expr<'a, 'tcx>( } Res::Def(DefKind::ConstParam, def_id) => { - let node_id = cx.tcx.hir().as_local_node_id(def_id).unwrap(); - let item_id = cx.tcx.hir().get_parent_node(node_id); - let item_def_id = cx.tcx.hir().local_def_id(item_id); + let hir_id = cx.tcx.hir().as_local_hir_id(def_id).unwrap(); + let item_id = cx.tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_def_id = cx.tcx.hir().local_def_id_from_hir_id(item_id); let generics = cx.tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&cx.tcx.hir().local_def_id(node_id)]; - let name = cx.tcx.hir().name(node_id).as_interned_str(); + let local_def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id); + let index = generics.param_def_id_to_index[&local_def_id]; + let name = cx.tcx.hir().name_by_hir_id(hir_id).as_interned_str(); let val = ConstValue::Param(ty::ParamConst::new(index, name)); ExprKind::Literal { literal: cx.tcx.mk_const( diff --git a/src/librustc_mir/interpret/validity.rs b/src/librustc_mir/interpret/validity.rs index 8a8cc0fe1d174..03ccbdb14b737 100644 --- a/src/librustc_mir/interpret/validity.rs +++ b/src/librustc_mir/interpret/validity.rs @@ -175,8 +175,8 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M // Sometimes the index is beyond the number of upvars (seen // for a generator). if let Some((&var_hir_id, _)) = upvars.get_index(field) { - let var_node_id = self.ecx.tcx.hir().hir_to_node_id(var_hir_id); - if let hir::Node::Binding(pat) = self.ecx.tcx.hir().get(var_node_id) { + let node = self.ecx.tcx.hir().get_by_hir_id(var_hir_id); + if let hir::Node::Binding(pat) = node { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { name = Some(ident.name); } diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 7230b69468126..3adee156eb175 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -165,7 +165,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_nested_body(&mut self, body_id: hir::BodyId) -> Promotability { let item_id = self.tcx.hir().body_owner(body_id); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); let outer_in_fn = self.in_fn; let outer_tables = self.tables; @@ -175,7 +175,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { self.in_fn = false; self.in_static = false; - match self.tcx.hir().body_owner_kind(item_id) { + match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => self.in_fn = true, hir::BodyOwnerKind::Static(_) => self.in_static = true, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 892a7b1f73015..97124e5347716 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -2196,12 +2196,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(def_id) = self.const_param_def_id(expr) { // Find the name and index of the const parameter by indexing the generics of the // parent item and construct a `ParamConst`. - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); - let item_id = tcx.hir().get_parent_node(node_id); - let item_def_id = tcx.hir().local_def_id(item_id); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let item_id = tcx.hir().get_parent_node_by_hir_id(hir_id); + let item_def_id = tcx.hir().local_def_id_from_hir_id(item_id); let generics = tcx.generics_of(item_def_id); - let index = generics.param_def_id_to_index[&tcx.hir().local_def_id(node_id)]; - let name = tcx.hir().name(node_id).as_interned_str(); + let index = generics.param_def_id_to_index[&tcx.hir().local_def_id_from_hir_id(hir_id)]; + let name = tcx.hir().name_by_hir_id(hir_id).as_interned_str(); const_.val = ConstValue::Param(ty::ParamConst::new(index, name)); } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ecf7860367bec..c4a834dd600a4 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2517,9 +2517,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Some(&t) => t, None if self.is_tainted_by_errors() => self.tcx.types.err, None => { - 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), + id, self.tcx.hir().hir_to_string(id), self.tag()); } } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 5be822897407b..1e33551b2560f 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -34,7 +34,7 @@ use syntax_pos::Span; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn resolve_type_vars_in_body(&self, body: &'tcx hir::Body) -> &'tcx ty::TypeckTables<'tcx> { let item_id = self.tcx.hir().body_owner(body.id()); - let item_def_id = self.tcx.hir().local_def_id(item_id); + let item_def_id = self.tcx.hir().local_def_id_from_hir_id(item_id); // This attribute causes us to dump some writeback information // in the form of errors, which is uSymbolfor unit tests. @@ -45,10 +45,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_node_id(arg.pat.span, arg.hir_id); } // Type only exists for constants and statics, not functions. - match self.tcx.hir().body_owner_kind(item_id) { + match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => { - let item_hir_id = self.tcx.hir().node_to_hir_id(item_id); - wbcx.visit_node_id(body.value.span, item_hir_id); + wbcx.visit_node_id(body.value.span, item_id); } hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (), } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d4b2c200297d2..1273fcfc2573c 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -395,7 +395,7 @@ fn is_param<'tcx>(tcx: TyCtxt<'tcx>, ast_ty: &hir::Ty, param_id: hir::HirId) -> } fn convert_item<'tcx>(tcx: TyCtxt<'tcx>, item_id: hir::HirId) { - let it = tcx.hir().expect_item_by_hir_id(item_id); + let it = tcx.hir().expect_item(item_id); debug!("convert: item {} with id {}", it.ident, it.hir_id); let def_id = tcx.hir().local_def_id_from_hir_id(item_id); match it.node { From d996c4d5a383744ec7550b59943b5744f4bcd122 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Fri, 14 Jun 2019 18:58:55 +0200 Subject: [PATCH 2/8] remove _by_hir_id if there is no NodeId counterpart --- src/librustc/cfg/construct.rs | 2 +- src/librustc/hir/intravisit.rs | 2 +- src/librustc/hir/map/mod.rs | 28 +++++++++---------- src/librustc/hir/upvars.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 10 +++---- .../error_reporting/nice_region_error/util.rs | 4 +-- src/librustc/lint/context.rs | 2 +- src/librustc/lint/mod.rs | 2 +- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/liveness.rs | 4 +-- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/reachable.rs | 6 ++-- src/librustc/middle/region.rs | 8 +++--- src/librustc/middle/resolve_lifetime.rs | 14 +++++----- src/librustc/mir/mod.rs | 4 +-- src/librustc/mir/mono.rs | 2 +- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/util.rs | 2 +- src/librustc/ty/mod.rs | 14 +++++----- src/librustc/ty/print/pretty.rs | 4 +-- .../borrowck/gather_loans/move_error.rs | 2 +- src/librustc_borrowck/borrowck/mod.rs | 16 +++++------ src/librustc_codegen_ssa/mono_item.rs | 2 +- src/librustc_driver/pretty.rs | 2 +- src/librustc_lint/nonstandard_style.rs | 2 +- src/librustc_lint/types.rs | 2 +- src/librustc_lint/unused.rs | 2 +- src/librustc_metadata/encoder.rs | 6 ++-- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/borrow_check/move_errors.rs | 2 +- .../error_reporting/region_name.rs | 2 +- .../region_infer/error_reporting/var_name.rs | 2 +- .../borrow_check/nll/universal_regions.rs | 2 +- src/librustc_mir/build/mod.rs | 14 +++++----- src/librustc_mir/hair/cx/block.rs | 2 +- src/librustc_mir/hair/cx/mod.rs | 4 +-- src/librustc_mir/hair/pattern/check_match.rs | 6 ++-- src/librustc_mir/lints.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/monomorphize/item.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 8 +++--- src/librustc_mir/transform/inline.rs | 2 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_privacy/lib.rs | 16 +++++------ src/librustc_typeck/check/callee.rs | 2 +- src/librustc_typeck/check/compare_method.rs | 2 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/method/suggest.rs | 8 +++--- src/librustc_typeck/check/mod.rs | 16 +++++------ src/librustc_typeck/check/regionck.rs | 2 +- src/librustc_typeck/check/wfcheck.rs | 2 +- src/librustc_typeck/check/writeback.rs | 8 +++--- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 14 +++++----- src/librustc_typeck/collect.rs | 18 ++++++------ src/librustc_typeck/variance/mod.rs | 2 +- src/librustdoc/clean/inline.rs | 4 +-- src/librustdoc/clean/mod.rs | 10 +++---- src/librustdoc/visit_ast.rs | 10 +++---- .../auxiliary/issue-40001-plugin.rs | 2 +- 62 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 8eea01cc4acca..8f0f832b6c418 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -358,7 +358,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { args: I) -> CFGIndex { let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let ret = self.straightline(call_expr, func_or_rcvr_exit, args); - let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id); + let m = self.tcx.hir().get_module_parent(call_expr.hir_id); if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) { self.add_unreachable_node() } else { diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index f4f9d6261de48..666cfc3f6dcac 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -171,7 +171,7 @@ pub trait Visitor<'v> : Sized { /// but cannot supply a `Map`; see `nested_visit_map` for advice. #[allow(unused_variables)] fn visit_nested_item(&mut self, id: ItemId) { - let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item_by_hir_id(id.id)); + let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id)); if let Some(item) = opt_item { self.visit_item(item); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 680fe2866bcea..5a45f04b63719 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -435,7 +435,7 @@ impl<'hir> Map<'hir> { /// Given a `HirId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. - pub fn maybe_body_owned_by_by_hir_id(&self, hir_id: HirId) -> Option { + pub fn maybe_body_owned_by(&self, hir_id: HirId) -> Option { if let Some(entry) = self.find_entry(hir_id) { if self.dep_graph.is_fully_enabled() { let hir_id_owner = hir_id.owner; @@ -451,13 +451,13 @@ impl<'hir> Map<'hir> { /// Given a body owner's id, returns the `BodyId` associated with it. pub fn body_owned_by(&self, id: HirId) -> BodyId { - self.maybe_body_owned_by_by_hir_id(id).unwrap_or_else(|| { - span_bug!(self.span_by_hir_id(id), "body_owned_by: {} has no associated body", + self.maybe_body_owned_by(id).unwrap_or_else(|| { + span_bug!(self.span(id), "body_owned_by: {} has no associated body", self.hir_to_string(id)); }) } - pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind { + pub fn body_owner_kind(&self, id: HirId) -> BodyOwnerKind { match self.get_by_hir_id(id) { Node::Item(&Item { node: ItemKind::Const(..), .. }) | Node::TraitItem(&TraitItem { node: TraitItemKind::Const(..), .. }) | @@ -548,7 +548,7 @@ impl<'hir> Map<'hir> { let module = &self.forest.krate.modules[&node_id]; for id in &module.items { - visitor.visit_item(self.expect_item_by_hir_id(*id)); + visitor.visit_item(self.expect_item(*id)); } for id in &module.trait_items { @@ -784,7 +784,7 @@ impl<'hir> Map<'hir> { /// Returns the `DefId` of `id`'s nearest module parent, or `id` itself if no /// module parent is in this map. - pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId { + pub fn get_module_parent(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_module_parent_node(id)) } @@ -860,11 +860,11 @@ impl<'hir> Map<'hir> { Some(scope) } - pub fn get_parent_did_by_hir_id(&self, id: HirId) -> DefId { + pub fn get_parent_did(&self, id: HirId) -> DefId { self.local_def_id_from_hir_id(self.get_parent_item(id)) } - pub fn get_foreign_abi_by_hir_id(&self, hir_id: HirId) -> Abi { + pub fn get_foreign_abi(&self, hir_id: HirId) -> Abi { let parent = self.get_parent_item(hir_id); if let Some(entry) = self.find_entry(parent) { if let Entry { @@ -877,7 +877,7 @@ impl<'hir> Map<'hir> { bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) } - pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { + pub fn expect_item(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, _ => bug!("expected item, found {}", self.hir_to_string(id)) @@ -965,7 +965,7 @@ impl<'hir> Map<'hir> { /// Given a node ID, gets a list of attributes associated with the AST /// corresponding to the node-ID. - pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] { + pub fn attrs(&self, id: HirId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find_entry(id).map(|entry| entry.node) { Some(Node::Local(l)) => Some(&l.attrs[..]), @@ -981,7 +981,7 @@ impl<'hir> Map<'hir> { Some(Node::GenericParam(param)) => Some(¶m.attrs[..]), // Unit/tuple structs/variants take the attributes straight from // the struct/variant definition. - Some(Node::Ctor(..)) => return self.attrs_by_hir_id(self.get_parent_item(id)), + Some(Node::Ctor(..)) => return self.attrs(self.get_parent_item(id)), Some(Node::Crate) => Some(&self.forest.krate.attrs[..]), _ => None }; @@ -1028,7 +1028,7 @@ impl<'hir> Map<'hir> { }) } - pub fn span_by_hir_id(&self, hir_id: HirId) -> Span { + pub fn span(&self, hir_id: HirId) -> Span { self.read(hir_id); // reveals span from node match self.find_entry(hir_id).map(|entry| entry.node) { Some(Node::Item(item)) => item.span, @@ -1068,7 +1068,7 @@ impl<'hir> Map<'hir> { } pub fn span_if_local(&self, id: DefId) -> Option { - self.as_local_hir_id(id).map(|id| self.span_by_hir_id(id)) + self.as_local_hir_id(id).map(|id| self.span(id)) } pub fn hir_to_string(&self, id: HirId) -> String { @@ -1221,7 +1221,7 @@ pub fn map_crate<'hir>(sess: &crate::session::Session, impl<'hir> print::PpAnn for Map<'hir> { fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) -> io::Result<()> { match nested { - Nested::Item(id) => state.print_item(self.expect_item_by_hir_id(id.id)), + Nested::Item(id) => state.print_item(self.expect_item(id.id)), Nested::TraitItem(id) => state.print_trait_item(self.trait_item(id)), Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)), Nested::Body(id) => state.print_expr(&self.body(id).value), diff --git a/src/librustc/hir/upvars.rs b/src/librustc/hir/upvars.rs index 662bde43c569c..54b4435573baa 100644 --- a/src/librustc/hir/upvars.rs +++ b/src/librustc/hir/upvars.rs @@ -15,7 +15,7 @@ pub fn provide(providers: &mut Providers<'_>) { } let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let body = tcx.hir().body(tcx.hir().maybe_body_owned_by_by_hir_id(hir_id)?); + let body = tcx.hir().body(tcx.hir().maybe_body_owned_by(hir_id)?); let mut local_collector = LocalCollector::default(); local_collector.visit_body(body); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 73bd37d53fe28..321c06897de11 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -191,7 +191,7 @@ impl<'tcx> TyCtxt<'tcx> { }; let (prefix, span) = match *region { ty::ReEarlyBound(ref br) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(br.name)) @@ -204,7 +204,7 @@ impl<'tcx> TyCtxt<'tcx> { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => { - let mut sp = cm.def_span(self.hir().span_by_hir_id(node)); + let mut sp = cm.def_span(self.hir().span(node)); if let Some(param) = self.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) @@ -216,11 +216,11 @@ impl<'tcx> TyCtxt<'tcx> { ty::ReFree(ref fr) => match fr.bound_region { ty::BrAnon(idx) => ( format!("the anonymous lifetime #{} defined on", idx + 1), - self.hir().span_by_hir_id(node), + self.hir().span(node), ), _ => ( format!("the lifetime {} as defined on", region), - cm.def_span(self.hir().span_by_hir_id(node)), + cm.def_span(self.hir().span(node)), ), }, _ => bug!(), @@ -1338,7 +1338,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { if let Node::GenericParam(ref param) = hir.get_by_hir_id(id) { has_bounds = !param.bounds.is_empty(); } - let sp = hir.span_by_hir_id(id); + let sp = hir.span(id); // `sp` only covers `T`, change it so that it covers // `T:` when appropriate let is_impl_trait = bound_kind.to_string().starts_with("impl "); diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index 061d74416c57f..f33f917392653 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -52,7 +52,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { let hir = &self.tcx().hir(); if let Some(hir_id) = hir.as_local_hir_id(id) { - if let Some(body_id) = hir.maybe_body_owned_by_by_hir_id(hir_id) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { let body = hir.body(body_id); let owner_id = hir.body_owner(body_id); let fn_decl = hir.fn_decl_by_hir_id(owner_id).unwrap(); @@ -63,7 +63,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { .filter_map(|(index, arg)| { // May return None; sometimes the tables are not yet populated. let ty_hir_id = fn_decl.inputs[index].hir_id; - let arg_ty_span = hir.span_by_hir_id(ty_hir_id); + let arg_ty_span = hir.span(ty_hir_id); let ty = tables.node_type_opt(arg.hir_id)?; let mut found_anon_region = false; let new_arg_ty = self.tcx().fold_regions(&ty, &mut false, |r, _| { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 468d909e5497b..e90f4ca94c625 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -1399,7 +1399,7 @@ fn late_lint_mod_pass<'tcx, T: for<'a> LateLintPass<'a, 'tcx>>( // Visit the crate attributes if hir_id == hir::CRATE_HIR_ID { - walk_list!(cx, visit_attribute, tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID)); + walk_list!(cx, visit_attribute, tcx.hir().attrs(hir::CRATE_HIR_ID)); } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 70c0e83517af0..041944d887bd9 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -762,7 +762,7 @@ pub fn struct_lint_level<'a>(sess: &'a Session, } pub fn maybe_lint_level_root(tcx: TyCtxt<'_>, id: hir::HirId) -> bool { - let attrs = tcx.hir().attrs_by_hir_id(id); + let attrs = tcx.hir().attrs(id); attrs.iter().any(|attr| Level::from_symbol(attr.name_or_empty()).is_some()) } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0356e7e10724d..63503f58156bc 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -292,7 +292,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &'tcx hir::Ty) { match ty.node { TyKind::Def(item_id, _) => { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); intravisit::walk_item(self, item); } _ => () diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 29c624575c3c2..3d2bc6c7bf882 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1171,7 +1171,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Call(ref f, ref args) => { - let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1182,7 +1182,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::MethodCall(.., ref args) => { - let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); + let m = self.ir.tcx.hir().get_module_parent(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index cf304ebf3cbf4..a856430e68a23 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -358,7 +358,7 @@ impl MutabilityCategory { } _ => span_bug!(p.span, "expected identifier pattern") }, - _ => span_bug!(tcx.hir().span_by_hir_id(id), "expected identifier pattern") + _ => span_bug!(tcx.hir().span(id), "expected identifier pattern") }; debug!("MutabilityCategory::{}(tcx, id={:?}) => {:?}", "from_local", id, ret); diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 363ccd74c08d9..2285beb375859 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -174,12 +174,12 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } else { let impl_did = self.tcx .hir() - .get_parent_did_by_hir_id(hir_id); + .get_parent_did(hir_id); // Check the impl. If the generics on the self // type of the impl require inlining, this method // does too. let impl_hir_id = self.tcx.hir().as_local_hir_id(impl_did).unwrap(); - match self.tcx.hir().expect_item_by_hir_id(impl_hir_id).node { + match self.tcx.hir().expect_item(impl_hir_id).node { hir::ItemKind::Impl(..) => { let generics = self.tcx.generics_of(impl_did); generics.requires_monomorphization(self.tcx) @@ -296,7 +296,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { self.visit_nested_body(body); } hir::ImplItemKind::Method(_, body) => { - let did = self.tcx.hir().get_parent_did_by_hir_id(search_item); + let did = self.tcx.hir().get_parent_did(search_item); if method_might_be_inlined(self.tcx, impl_item, did) { self.visit_nested_body(body) } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 708bd6f735d89..dfab8e36bf9d1 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -188,7 +188,7 @@ impl Scope { if hir_id == hir::DUMMY_HIR_ID { return DUMMY_SP; } - let span = tcx.hir().span_by_hir_id(hir_id); + let span = tcx.hir().span(hir_id); if let ScopeData::Remainder(first_statement_index) = self.data { if let Node::Block(ref blk) = tcx.hir().get_by_hir_id(hir_id) { // Want span for scope starting after the @@ -649,7 +649,7 @@ impl<'tcx> ScopeTree { let param_owner = tcx.parent(br.def_id).unwrap(); let param_owner_id = tcx.hir().as_local_hir_id(param_owner).unwrap(); - let scope = tcx.hir().maybe_body_owned_by_by_hir_id(param_owner_id).map(|body_id| { + let scope = tcx.hir().maybe_body_owned_by(param_owner_id).map(|body_id| { tcx.hir().body(body_id).value.hir_id.local_id }).unwrap_or_else(|| { // The lifetime was defined on node that doesn't own a body, @@ -1277,7 +1277,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The body of the every fn is a root scope. self.cx.parent = self.cx.var_parent; - if self.tcx.hir().body_owner_kind_by_hir_id(owner_id).is_fn_or_closure() { + if self.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() { self.visit_expr(&body.value) } else { // Only functions have an outer terminating (drop) scope, while @@ -1336,7 +1336,7 @@ fn region_scope_tree<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ScopeTree } let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by_by_hir_id(id) { + let scope_tree = if let Some(body_id) = tcx.hir().maybe_body_owned_by(id) { let mut visitor = RegionResolutionVisitor { tcx, scope_tree: ScopeTree::default(), diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index b350f15664d44..6f2c4b66f5ec4 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -625,7 +625,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // `abstract type MyAnonTy<'b>: MyTrait<'b>;` // ^ ^ this gets resolved in the scope of // the exist_ty generics - let (generics, bounds) = match self.tcx.hir().expect_item_by_hir_id(item_id.id).node + let (generics, bounds) = match self.tcx.hir().expect_item(item_id.id).node { // named existential types are reached via TyKind::Path // this arm is for `impl Trait` in the types of statics, constants and locals @@ -1236,7 +1236,7 @@ fn extract_labels(ctxt: &mut LifetimeContext<'_, '_>, body: &hir::Body) { signal_shadowing_problem( tcx, label.name, - original_lifetime(tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(tcx.hir().span(hir_id)), shadower_label(label.span), ); return; @@ -1590,7 +1590,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let Some(parent_hir_id) = self.tcx.hir() .as_local_hir_id(parent_def_id) { // lifetimes in `derive` expansions don't count (Issue #53738) - if self.tcx.hir().attrs_by_hir_id(parent_hir_id).iter() + if self.tcx.hir().attrs(parent_hir_id).iter() .any(|attr| attr.check_name(sym::automatically_derived)) { continue; } @@ -1690,7 +1690,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // Find the start of nested early scopes, e.g., in methods. let mut index = 0; if let Some(parent_id) = parent_id { - let parent = self.tcx.hir().expect_item_by_hir_id(parent_id); + let parent = self.tcx.hir().expect_item(parent_id); if sub_items_have_self_param(&parent.node) { index += 1; // Self comes before lifetimes } @@ -2065,7 +2065,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx .hir() - .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) + .expect_item(self.tcx.hir().get_parent_item(parent)) .node { assoc_item_kind = trait_items @@ -2085,7 +2085,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx .hir() - .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) + .expect_item(self.tcx.hir().get_parent_item(parent)) .node { impl_self = Some(self_ty); @@ -2629,7 +2629,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { signal_shadowing_problem( self.tcx, param.name.ident().name, - original_lifetime(self.tcx.hir().span_by_hir_id(hir_id)), + original_lifetime(self.tcx.hir().span(hir_id)), shadower_lifetime(¶m), ); return; diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3d96acbe7be97..1d5c1cb927d28 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2565,7 +2565,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { let name = if tcx.sess.opts.debugging_opts.span_free_formats { format!("[closure@{:?}]", hir_id) } else { - format!("[closure@{:?}]", tcx.hir().span_by_hir_id(hir_id)) + format!("[closure@{:?}]", tcx.hir().span(hir_id)) }; let mut struct_fmt = fmt.debug_struct(&name); @@ -2585,7 +2585,7 @@ impl<'tcx> Debug for Rvalue<'tcx> { AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { let name = format!("[generator@{:?}]", - tcx.hir().span_by_hir_id(hir_id)); + tcx.hir().span(hir_id)); let mut struct_fmt = fmt.debug_struct(&name); if let Some(upvars) = tcx.upvars(def_id) { diff --git a/src/librustc/mir/mono.rs b/src/librustc/mir/mono.rs index 39ae48b303abf..432a61de6cb98 100644 --- a/src/librustc/mir/mono.rs +++ b/src/librustc/mir/mono.rs @@ -218,7 +218,7 @@ impl<'tcx> MonoItem<'tcx> { MonoItem::GlobalAsm(hir_id) => { Some(hir_id) } - }.map(|hir_id| tcx.hir().span_by_hir_id(hir_id)) + }.map(|hir_id| tcx.hir().span(hir_id)) } } diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f886794be6282..dcf69fee0e16d 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { } Node::Ctor(ref variant_data) => { let span = variant_data.ctor_hir_id() - .map(|hir_id| self.tcx.hir().span_by_hir_id(hir_id)) + .map(|hir_id| self.tcx.hir().span(hir_id)) .unwrap_or(DUMMY_SP); let span = self.tcx.sess.source_map().def_span(span); diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index b6a1ab9fe709a..2d295679be324 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -654,7 +654,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn impl_is_default(self, node_item_def_id: DefId) -> bool { match self.hir().as_local_hir_id(node_item_def_id) { Some(hir_id) => { - let item = self.hir().expect_item_by_hir_id(hir_id); + let item = self.hir().expect_item(hir_id); if let hir::ItemKind::Impl(_, _, defaultness, ..) = item.node { defaultness.is_default() } else { diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index c932586c078bd..361410380e8f8 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -277,7 +277,7 @@ impl Visibility { def => Visibility::Restricted(def.def_id()), }, hir::VisibilityKind::Inherited => { - Visibility::Restricted(tcx.hir().get_module_parent_by_hir_id(id)) + Visibility::Restricted(tcx.hir().get_module_parent(id)) } } } @@ -3016,7 +3016,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Gets the attributes of a definition. pub fn get_attrs(self, did: DefId) -> Attributes<'tcx> { if let Some(id) = self.hir().as_local_hir_id(did) { - Attributes::Borrowed(self.hir().attrs_by_hir_id(id)) + Attributes::Borrowed(self.hir().attrs(id)) } else { Attributes::Owned(self.item_attrs(did)) } @@ -3068,7 +3068,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn span_of_impl(self, impl_did: DefId) -> Result { if impl_did.is_local() { let hir_id = self.hir().as_local_hir_id(impl_did).unwrap(); - Ok(self.hir().span_by_hir_id(hir_id)) + Ok(self.hir().span(hir_id)) } else { Err(self.crate_name(impl_did.krate)) } @@ -3103,7 +3103,7 @@ impl<'tcx> TyCtxt<'tcx> { let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) { Some(actual_expansion) => self.hir().definitions().parent_module_of_macro_def(actual_expansion), - None => self.hir().get_module_parent_by_hir_id(block), + None => self.hir().get_module_parent(block), }; (ident, scope) } @@ -3129,7 +3129,7 @@ fn associated_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AssocItem { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let parent_id = tcx.hir().get_parent_item(id); let parent_def_id = tcx.hir().local_def_id_from_hir_id(parent_id); - let parent_item = tcx.hir().expect_item_by_hir_id(parent_id); + let parent_item = tcx.hir().expect_item(parent_id); match parent_item.node { hir::ItemKind::Impl(.., ref impl_item_refs) => { if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.hir_id == id) { @@ -3186,7 +3186,7 @@ fn adt_sized_constraint<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> AdtSizedConst fn associated_item_def_ids<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [DefId] { let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(id); + let item = tcx.hir().expect_item(id); match item.node { hir::ItemKind::Trait(.., ref trait_item_refs) => { tcx.arena.alloc_from_iter( @@ -3266,7 +3266,7 @@ fn param_env<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ParamEnv<'tcx> { ); let body_id = tcx.hir().as_local_hir_id(def_id).map_or(hir::DUMMY_HIR_ID, |id| { - tcx.hir().maybe_body_owned_by_by_hir_id(id).map_or(id, |body| body.hir_id) + tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.hir_id) }); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) diff --git a/src/librustc/ty/print/pretty.rs b/src/librustc/ty/print/pretty.rs index b79d7f06cd6aa..d143cc3e6092d 100644 --- a/src/librustc/ty/print/pretty.rs +++ b/src/librustc/ty/print/pretty.rs @@ -589,7 +589,7 @@ pub trait PrettyPrinter<'tcx>: // FIXME(eddyb) should use `def_span`. if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) { - p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id))); + p!(write("@{:?}", self.tcx().hir().span(hir_id))); let mut sep = " "; for (&var_id, upvar_ty) in self.tcx().upvars(did) .as_ref() @@ -631,7 +631,7 @@ pub trait PrettyPrinter<'tcx>: if self.tcx().sess.opts.debugging_opts.span_free_formats { p!(write("@{:?}", hir_id)); } else { - p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id))); + p!(write("@{:?}", self.tcx().hir().span(hir_id))); } let mut sep = " "; for (&var_id, upvar_ty) in self.tcx().upvars(did) diff --git a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs index 9a00c43be3fbb..58be2cf76c724 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/move_error.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/move_error.rs @@ -88,7 +88,7 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr } } if let NoteClosureEnv(upvar_id) = error.move_from.note { - err.span_label(bccx.tcx.hir().span_by_hir_id(upvar_id.var_path.hir_id), + err.span_label(bccx.tcx.hir().span(upvar_id.var_path.hir_id), "captured outer variable"); } err.emit(); diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 9429fde279086..cc9c83de179c8 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -699,7 +699,7 @@ impl BorrowckCtxt<'_, 'tcx> { } move_data::MoveExpr | - move_data::MovePat => (self.tcx.hir().span_by_hir_id(hir_id), ""), + move_data::MovePat => (self.tcx.hir().span(hir_id), ""), move_data::Captured => (match self.tcx.hir().expect_expr_by_hir_id(hir_id).node { @@ -828,7 +828,7 @@ impl BorrowckCtxt<'_, 'tcx> { let mut db = self.cannot_assign(error_span, &descr, Origin::Ast); if let mc::NoteClosureEnv(upvar_id) = err.cmt.note { let hir_id = upvar_id.var_path.hir_id; - let sp = self.tcx.hir().span_by_hir_id(hir_id); + let sp = self.tcx.hir().span(hir_id); let fn_closure_msg = "`Fn` closures cannot capture their enclosing \ environment for modifications"; match (self.tcx.sess.source_map().span_to_snippet(sp), &err.cmt.cat) { @@ -1117,7 +1117,7 @@ impl BorrowckCtxt<'_, 'tcx> { "consider changing this closure to take self by mutable reference" }; let hir_id = self.tcx.hir().local_def_id_to_hir_id(id); - let help_span = self.tcx.hir().span_by_hir_id(hir_id); + let help_span = self.tcx.hir().span(hir_id); self.cannot_act_on_capture_in_sharable_fn(span, prefix, (help_span, help_msg), @@ -1223,7 +1223,7 @@ impl BorrowckCtxt<'_, 'tcx> { Some(ImmutabilityBlame::LocalDeref(hir_id)) => { match self.local_binding_mode(hir_id) { ty::BindByReference(..) => { - let let_span = self.tcx.hir().span_by_hir_id(hir_id); + let let_span = self.tcx.hir().span(hir_id); let suggestion = suggest_ref_mut(self.tcx, let_span); if let Some(replace_str) = suggestion { db.span_suggestion( @@ -1271,7 +1271,7 @@ impl BorrowckCtxt<'_, 'tcx> { db: &mut DiagnosticBuilder<'_>, borrowed_hir_id: hir::HirId, binding_hir_id: hir::HirId) { - let let_span = self.tcx.hir().span_by_hir_id(binding_hir_id); + let let_span = self.tcx.hir().span(binding_hir_id); if let ty::BindByValue(..) = self.local_binding_mode(binding_hir_id) { if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(let_span) { let (ty, is_implicit_self) = self.local_ty(binding_hir_id); @@ -1289,7 +1289,7 @@ impl BorrowckCtxt<'_, 'tcx> { { let borrow_expr_id = self.tcx.hir().get_parent_node_by_hir_id(borrowed_hir_id); db.span_suggestion( - self.tcx.hir().span_by_hir_id(borrow_expr_id), + self.tcx.hir().span(borrow_expr_id), "consider removing the `&mut`, as it is an \ immutable binding to a mutable reference", snippet, @@ -1360,7 +1360,7 @@ impl BorrowckCtxt<'_, 'tcx> { if *kind == ty::ClosureKind::Fn { let closure_hir_id = self.tcx.hir().local_def_id_to_hir_id(upvar_id.closure_expr_id); - db.span_help(self.tcx.hir().span_by_hir_id(closure_hir_id), + db.span_help(self.tcx.hir().span(closure_hir_id), "consider changing this closure to take \ self by mutable reference"); } @@ -1369,7 +1369,7 @@ impl BorrowckCtxt<'_, 'tcx> { if let Categorization::Deref(..) = err.cmt.cat { db.span_label(*error_span, "cannot borrow as mutable"); } else if let Categorization::Local(local_id) = err.cmt.cat { - let span = self.tcx.hir().span_by_hir_id(local_id); + let span = self.tcx.hir().span(local_id); if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) { if snippet.starts_with("ref mut ") || snippet.starts_with("&mut ") { db.span_label(*error_span, "cannot reborrow mutably"); diff --git a/src/librustc_codegen_ssa/mono_item.rs b/src/librustc_codegen_ssa/mono_item.rs index 11e9a48133d9a..dc50c0e19efbf 100644 --- a/src/librustc_codegen_ssa/mono_item.rs +++ b/src/librustc_codegen_ssa/mono_item.rs @@ -29,7 +29,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id)); } MonoItem::GlobalAsm(hir_id) => { - let item = cx.tcx().hir().expect_item_by_hir_id(hir_id); + let item = cx.tcx().hir().expect_item(hir_id); if let hir::ItemKind::GlobalAsm(ref ga) = item.node { cx.codegen_global_asm(ga); } else { diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index ef416dbe62b8e..683da5865cda4 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -923,7 +923,7 @@ fn print_with_analysis<'tcx>( node); let hir_id = tcx.hir().node_to_hir_id(nodeid); - tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &message) + tcx.sess.span_fatal(tcx.hir().span(hir_id), &message) } } } diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 903a2d6801230..b221b8ed30c59 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -254,7 +254,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonSnakeCase { let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name { Some(Ident::from_str(name)) } else { - attr::find_by_name(&cx.tcx.hir().attrs_by_hir_id(hir::CRATE_HIR_ID), sym::crate_name) + attr::find_by_name(&cx.tcx.hir().attrs(hir::CRATE_HIR_ID), sym::crate_name) .and_then(|attr| attr.meta()) .and_then(|meta| { meta.name_value_literal().and_then(|lit| { diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index a843ee6d45d8f..9fc23e45d203c 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -921,7 +921,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImproperCTypes { fn check_foreign_item(&mut self, cx: &LateContext<'_, '_>, it: &hir::ForeignItem) { let mut vis = ImproperCTypesVisitor { cx }; - let abi = cx.tcx.hir().get_foreign_abi_by_hir_id(it.hir_id); + let abi = cx.tcx.hir().get_foreign_abi(it.hir_id); if abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic { match it.node { hir::ForeignItemKind::Fn(ref decl, _, _) => { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index d540b3f7e40a3..f84ce2f015edf 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -136,7 +136,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { descr_post_path: &str, ) -> bool { if ty.is_unit() || cx.tcx.is_ty_uninhabited_from( - cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty) + cx.tcx.hir().get_module_parent(expr.hir_id), ty) { return true; } diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index dbf140afda24d..b52b6dfbb5e12 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -579,7 +579,7 @@ impl EncodeContext<'tcx> { }; let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); - let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis; + let enum_vis = &tcx.hir().expect_item(enum_id).vis; Entry { kind: EntryKind::Variant(self.lazy(&data)), @@ -632,7 +632,7 @@ impl EncodeContext<'tcx> { // Variant constructors have the same visibility as the parent enums, unless marked as // non-exhaustive, in which case they are lowered to `pub(crate)`. let enum_id = tcx.hir().as_local_hir_id(enum_did).unwrap(); - let enum_vis = &tcx.hir().expect_item_by_hir_id(enum_id).vis; + let enum_vis = &tcx.hir().expect_item(enum_id).vis; let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx); if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); @@ -751,7 +751,7 @@ impl EncodeContext<'tcx> { }; let struct_id = tcx.hir().as_local_hir_id(adt_def_id).unwrap(); - let struct_vis = &tcx.hir().expect_item_by_hir_id(struct_id).vis; + let struct_vis = &tcx.hir().expect_item(struct_id).vis; let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx); for field in &variant.fields { if ctor_vis.is_at_least(field.vis, tcx) { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 9c2ab91fe2f8b..c4a11efe5bce4 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -177,7 +177,7 @@ fn do_mir_borrowck<'a, 'tcx>( |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), )); - let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure(); + let locals_are_invalidated_at_exit = tcx.hir().body_owner_kind(id).is_fn_or_closure(); let borrow_set = Rc::new(BorrowSet::build( tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data)); diff --git a/src/librustc_mir/borrow_check/move_errors.rs b/src/librustc_mir/borrow_check/move_errors.rs index 402654c44ac15..d15229367251a 100644 --- a/src/librustc_mir/borrow_check/move_errors.rs +++ b/src/librustc_mir/borrow_check/move_errors.rs @@ -422,7 +422,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let upvar = &self.upvars[upvar_field.unwrap().index()]; let upvar_hir_id = upvar.var_hir_id; let upvar_name = upvar.name; - let upvar_span = self.infcx.tcx.hir().span_by_hir_id(upvar_hir_id); + let upvar_span = self.infcx.tcx.hir().span(upvar_hir_id); let place_name = self.describe_place(move_place).unwrap(); diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs index 61a13df47ffe6..46b690129ea25 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs @@ -310,7 +310,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { let scope = error_region.free_region_binding_scope(tcx); let node = tcx.hir().as_local_hir_id(scope).unwrap_or(hir::DUMMY_HIR_ID); - let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(node)); + let span = tcx.sess.source_map().def_span(tcx.hir().span(node)); if let Some(param) = tcx.hir() .get_generics(scope) .and_then(|generics| generics.get_named(name)) diff --git a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs index 6ce925cc7d12a..59fc4113794a4 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs @@ -73,7 +73,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { debug!("get_upvar_name_and_span_for_region: upvar_hir_id={:?}", upvar_hir_id); let upvar_name = tcx.hir().name_by_hir_id(upvar_hir_id); - let upvar_span = tcx.hir().span_by_hir_id(upvar_hir_id); + let upvar_span = tcx.hir().span(upvar_hir_id); debug!("get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}", upvar_name, upvar_span); diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index df0110ed3e39b..a236359f1d431 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -471,7 +471,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let tcx = self.infcx.tcx; let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); - match tcx.hir().body_owner_kind_by_hir_id(self.mir_hir_id) { + match tcx.hir().body_owner_kind(self.mir_hir_id) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { let defining_ty = if self.mir_def_id == closure_base_def_id { diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 280592e2b0164..a0e45caeb6b3b 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -55,10 +55,10 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { (*body_id, ty.span) } Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => { - (*body, tcx.hir().span_by_hir_id(*hir_id)) + (*body, tcx.hir().span(*hir_id)) } - _ => span_bug!(tcx.hir().span_by_hir_id(id), "can't build MIR for {:?}", def_id), + _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), }; tcx.infer_ctxt().enter(|infcx| { @@ -103,7 +103,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { let self_arg; if let Some(ref fn_decl) = tcx.hir().fn_decl_by_hir_id(owner_id) { let ty_hir_id = fn_decl.inputs[index].hir_id; - let ty_span = tcx.hir().span_by_hir_id(ty_hir_id); + let ty_span = tcx.hir().span(ty_hir_id); opt_ty_info = Some(ty_span); self_arg = if index == 0 && fn_decl.implicit_self.has_implicit_self() { match fn_decl.implicit_self { @@ -131,7 +131,7 @@ pub fn mir_build<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Body<'tcx> { ty::Generator(gen_def_id, gen_substs, ..) => gen_substs.sig(gen_def_id, tcx), _ => - span_bug!(tcx.hir().span_by_hir_id(id), + span_bug!(tcx.hir().span(id), "generator w/o generator type: {:?}", ty), }; (Some(gen_sig.yield_ty), gen_sig.return_ty) @@ -535,7 +535,7 @@ where let tcx = hir.tcx(); let tcx_hir = tcx.hir(); - let span = tcx_hir.span_by_hir_id(fn_id); + let span = tcx_hir.span(fn_id); let hir_tables = hir.tables(); let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id); @@ -650,7 +650,7 @@ fn construct_const<'a, 'tcx>( ) -> Body<'tcx> { let tcx = hir.tcx(); let owner_id = tcx.hir().body_owner(body_id); - let span = tcx.hir().span_by_hir_id(owner_id); + let span = tcx.hir().span(owner_id); let mut builder = Builder::new( hir, span, @@ -689,7 +689,7 @@ fn construct_error<'a, 'tcx>( body_id: hir::BodyId ) -> Body<'tcx> { let owner_id = hir.tcx().hir().body_owner(body_id); - let span = hir.tcx().hir().span_by_hir_id(owner_id); + let span = hir.tcx().hir().span(owner_id); let ty = hir.tcx().types.err; let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![], false); let source_info = builder.source_info(span); diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 63239a36a1753..d5932052d1aa3 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -49,7 +49,7 @@ fn mirror_stmts<'a, 'tcx>( for (index, stmt) in stmts.iter().enumerate() { let hir_id = stmt.hir_id; let opt_dxn_ext = cx.region_scope_tree.opt_destruction_scope(hir_id.local_id); - let stmt_span = StatementSpan(cx.tcx.hir().span_by_hir_id(hir_id)); + let stmt_span = StatementSpan(cx.tcx.hir().span(hir_id)); match stmt.node { hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index b6feac392f483..ff53cf02d8d15 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { let tcx = infcx.tcx; let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id); let tables = tcx.typeck_tables_of(src_def_id); - let body_owner_kind = tcx.hir().body_owner_kind_by_hir_id(src_id); + let body_owner_kind = tcx.hir().body_owner_kind(src_id); let constness = match body_owner_kind { hir::BodyOwnerKind::Const | @@ -65,7 +65,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { hir::BodyOwnerKind::Fn => hir::Constness::NotConst, }; - let attrs = tcx.hir().attrs_by_hir_id(src_id); + let attrs = tcx.hir().attrs(src_id); // Some functions always have overflow checks enabled, // however, they may not get codegen'd, depending on diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index e7fd308070c9b..159b526bdba65 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -161,7 +161,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } } - let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut have_errors = false; @@ -193,7 +193,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { // Then, if the match has no arms, check whether the scrutinee // is uninhabited. let pat_ty = self.tables.node_type(scrut.hir_id); - let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); + let module = self.tcx.hir().get_module_parent(scrut.hir_id); let mut def_span = None; let mut missing_variants = vec![]; if inlined_arms.is_empty() { @@ -261,7 +261,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) { - let module = self.tcx.hir().get_module_parent_by_hir_id(pat.hir_id); + let module = self.tcx.hir().get_module_parent(pat.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut patcx = PatternContext::new(self.tcx, self.param_env.and(self.identity_substs), diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 55151a9b33eb9..a7120888742d0 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -130,7 +130,7 @@ fn check_fn_for_unconditional_recursion( // recurs. if !reached_exit_without_self_call && !self_call_locations.is_empty() { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let sp = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(hir_id)); + let sp = tcx.sess.source_map().def_span(tcx.hir().span(hir_id)); let mut db = tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index e530c56ed6f3a..2e74ebcf061e2 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -455,7 +455,7 @@ fn check_recursion_limit<'tcx>( let error = format!("reached the recursion limit while instantiating `{}`", instance); if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { - tcx.sess.span_fatal(tcx.hir().span_by_hir_id(hir_id), &error); + tcx.sess.span_fatal(tcx.hir().span(hir_id), &error); } else { tcx.sess.fatal(&error); } diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 595e599c1150a..2bcf058ad7c35 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -193,7 +193,7 @@ pub trait MonoItemExt<'tcx>: fmt::Debug { MonoItem::GlobalAsm(hir_id) => { Some(hir_id) } - }.map(|hir_id| tcx.hir().span_by_hir_id(hir_id)) + }.map(|hir_id| tcx.hir().span(hir_id)) } } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 80a31efd0d3fe..32153f7bcd9cc 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -488,7 +488,7 @@ fn check_unused_unsafe<'a, 'tcx>( ) { let body_id = tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { - tcx.hir().maybe_body_owned_by_by_hir_id(hir_id) + tcx.hir().maybe_body_owned_by(hir_id) }); let body_id = match body_id { @@ -527,7 +527,7 @@ fn unsafety_check_result<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> UnsafetyChec let param_env = tcx.param_env(def_id); let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let (const_context, min_const_fn) = match tcx.hir().body_owner_kind_by_hir_id(id) { + let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => (tcx.is_const_fn(def_id), tcx.is_min_const_fn(def_id)), hir::BodyOwnerKind::Const | @@ -591,12 +591,12 @@ fn is_enclosed( } fn report_unused_unsafe(tcx: TyCtxt<'_>, used_unsafe: &FxHashSet, id: hir::HirId) { - let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)); + let span = tcx.sess.source_map().def_span(tcx.hir().span(id)); let msg = "unnecessary `unsafe` block"; let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg); db.span_label(span, msg); if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) { - db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)), + db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)), format!("because it's nested under this `unsafe` {}", kind)); } db.emit(); diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index f8e3fc2138d1e..5e6f1bc15f02a 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -70,7 +70,7 @@ impl Inliner<'tcx> { // Only do inlining into fn bodies. let id = self.tcx.hir().as_local_hir_id(self.source.def_id()).unwrap(); - if self.tcx.hir().body_owner_kind_by_hir_id(id).is_fn_or_closure() + if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() { for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated() { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 04dce326e69de..79bb2cfe08db3 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -208,7 +208,7 @@ fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> fn mir_validated(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(hir_id) { + if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind(hir_id) { // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. let _ = tcx.mir_const_qualif(def_id); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 8a8cc5080a855..b6abfdb7425aa 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1503,7 +1503,7 @@ impl MirPass for QualifyAndPromoteConstants { let def_id = src.def_id(); let id = tcx.hir().as_local_hir_id(def_id).unwrap(); let mut const_promoted_temps = None; - let mode = match tcx.hir().body_owner_kind_by_hir_id(id) { + let mode = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => Mode::NonConstFn, hir::BodyOwnerKind::Fn => { if tcx.is_const_fn(def_id) { diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 3adee156eb175..5397a4af8fa8f 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -175,7 +175,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { self.in_fn = false; self.in_static = false; - match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { + match self.tcx.hir().body_owner_kind(item_id) { hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => self.in_fn = true, hir::BodyOwnerKind::Static(_) => self.in_static = true, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index c2cb2f4d1745e..9eaa6f920f085 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -233,7 +233,7 @@ fn def_id_visibility<'tcx>( Node::Item(item) => &item.vis, Node::ForeignItem(foreign_item) => &foreign_item.vis, Node::TraitItem(..) | Node::Variant(..) => { - return def_id_visibility(tcx, tcx.hir().get_parent_did_by_hir_id(hir_id)); + return def_id_visibility(tcx, tcx.hir().get_parent_did(hir_id)); } Node::ImplItem(impl_item) => { match tcx.hir().get_by_hir_id(tcx.hir().get_parent_item(hir_id)) { @@ -255,7 +255,7 @@ fn def_id_visibility<'tcx>( tcx, parent_did, ); - let adt_def = tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)); + let adt_def = tcx.adt_def(tcx.hir().get_parent_did(hir_id)); let ctor_did = tcx.hir().local_def_id_from_hir_id( vdata.ctor_hir_id().unwrap()); let variant = adt_def.variant_with_ctor_id(ctor_did); @@ -294,7 +294,7 @@ fn def_id_visibility<'tcx>( // visibility to within the crate. if ctor_vis == ty::Visibility::Public { let adt_def = - tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)); + tcx.adt_def(tcx.hir().get_parent_did(hir_id)); if adt_def.non_enum_variant().is_field_list_non_exhaustive() { ctor_vis = ty::Visibility::Restricted(DefId::local(CRATE_DEF_INDEX)); @@ -311,7 +311,7 @@ fn def_id_visibility<'tcx>( } Node::Expr(expr) => { return (ty::Visibility::Restricted( - tcx.hir().get_module_parent_by_hir_id(expr.hir_id)), + tcx.hir().get_module_parent(expr.hir_id)), expr.span, "private") } node => bug!("unexpected node kind: {:?}", node) @@ -501,11 +501,11 @@ impl EmbargoVisitor<'tcx> { if let Some(item) = module.res .and_then(|res| res.mod_def_id()) .and_then(|def_id| self.tcx.hir().as_local_hir_id(def_id)) - .map(|module_hir_id| self.tcx.hir().expect_item_by_hir_id(module_hir_id)) + .map(|module_hir_id| self.tcx.hir().expect_item(module_hir_id)) { if let hir::ItemKind::Mod(m) = &item.node { for item_id in m.item_ids.as_ref() { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); let def_id = self.tcx.hir().local_def_id_from_hir_id(item_id.id); if !self.tcx.hygienic_eq(segment.ident, item.ident, def_id) { continue; } if let hir::ItemKind::Use(..) = item.node { @@ -764,7 +764,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { let module = if module_id == hir::CRATE_HIR_ID { &self.tcx.hir().krate().module } else if let hir::ItemKind::Mod(ref module) = - self.tcx.hir().expect_item_by_hir_id(module_id).node { + self.tcx.hir().expect_item(module_id).node { module } else { unreachable!() @@ -1690,7 +1690,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { tcx: self.tcx, item_id, item_def_id: self.tcx.hir().local_def_id_from_hir_id(item_id), - span: self.tcx.hir().span_by_hir_id(item_id), + span: self.tcx.hir().span(item_id), required_visibility, has_pub_restricted: self.has_pub_restricted, has_old_errors, diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 0207f18ac81d5..42c7ff607c55a 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -354,7 +354,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let def_span = match def { Res::Err => None, Res::Local(id) => { - Some(self.tcx.hir().span_by_hir_id(id)) + Some(self.tcx.hir().span(id)) }, _ => def .opt_def_id() diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 088ac0e8ba6c8..946082746f46f 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -813,7 +813,7 @@ fn compare_synthetic_generics<'tcx>( { if impl_synthetic != trait_synthetic { let impl_hir_id = tcx.hir().as_local_hir_id(impl_def_id).unwrap(); - let impl_span = tcx.hir().span_by_hir_id(impl_hir_id); + let impl_span = tcx.hir().span(impl_hir_id); let trait_span = tcx.def_span(trait_def_id); let mut err = struct_span_err!(tcx.sess, impl_span, diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 2003782e7adca..a2621abf44d8d 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -213,7 +213,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>( // repeated `contains` calls. if !assumptions_in_impl_context.contains(&predicate) { - let item_span = tcx.hir().span_by_hir_id(self_type_hir_id); + let item_span = tcx.hir().span(self_type_hir_id); struct_span_err!( tcx.sess, drop_impl_span, diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index 71bcf2bc05638..29b4fee138e82 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -264,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // local binding if let &QPath::Resolved(_, ref path) = &qpath { if let hir::def::Res::Local(hir_id) = path.res { - let span = tcx.hir().span_by_hir_id(hir_id); + let span = tcx.hir().span(hir_id); let snippet = tcx.sess.source_map().span_to_snippet(span); let filename = tcx.sess.source_map().span_to_filename(span); @@ -370,7 +370,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); if let Some((field, field_ty)) = field_receiver { - let scope = self.tcx.hir().get_module_parent_by_hir_id(self.body_id); + let scope = self.tcx.hir().get_module_parent(self.body_id); let is_accessible = field.vis.is_accessible_from(scope, self.tcx); if is_accessible { @@ -564,7 +564,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err: &mut DiagnosticBuilder<'_>, mut msg: String, candidates: Vec) { - let module_did = self.tcx.hir().get_module_parent_by_hir_id(self.body_id); + let module_did = self.tcx.hir().get_module_parent(self.body_id); let module_id = self.tcx.hir().as_local_hir_id(module_did).unwrap(); let krate = self.tcx.hir().krate(); let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id); @@ -897,7 +897,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> { } // Find a `use` statement. for item_id in &module.item_ids { - let item = self.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = self.tcx.hir().expect_item(item_id.id); match item.node { hir::ItemKind::Use(..) => { // Don't suggest placing a `use` before the prelude diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c4a834dd600a4..d4dbb68778ed2 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -622,7 +622,7 @@ impl Inherited<'a, 'tcx> { fn new(infcx: InferCtxt<'a, 'tcx>, def_id: DefId) -> Self { let tcx = infcx.tcx; let item_id = tcx.hir().as_local_hir_id(def_id); - let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by_by_hir_id(id)); + let body_id = item_id.and_then(|id| tcx.hir().maybe_body_owned_by(id)); let implicit_region_bound = body_id.map(|body_id| { let body = tcx.hir().body(body_id); tcx.mk_region(ty::ReScope(region::Scope { @@ -821,7 +821,7 @@ fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TypeckT } let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let span = tcx.hir().span_by_hir_id(id); + let span = tcx.hir().span(id); // Figure out what primary body this item has. let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| { @@ -1193,7 +1193,7 @@ fn check_fn<'a, 'tcx>( } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span_by_hir_id(fn_id); + let span = fcx.tcx.hir().span(fn_id); if inputs.len() == 1 { let arg_is_panic_info = match inputs[0].sty { ty::Ref(region, ty, mutbl) => match ty.sty { @@ -1246,7 +1246,7 @@ fn check_fn<'a, 'tcx>( } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span_by_hir_id(fn_id); + let span = fcx.tcx.hir().span(fn_id); if inputs.len() == 1 { let arg_is_alloc_layout = match inputs[0].sty { ty::Adt(ref adt, _) => { @@ -1909,11 +1909,11 @@ pub fn check_enum<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, vs: &'tcx [hir::Variant], i let variant_i_hir_id = tcx.hir().as_local_hir_id(variant_did).unwrap(); let variant_i = tcx.hir().expect_variant(variant_i_hir_id); let i_span = match variant_i.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), - None => tcx.hir().span_by_hir_id(variant_i_hir_id) + Some(ref expr) => tcx.hir().span(expr.hir_id), + None => tcx.hir().span(variant_i_hir_id) }; let span = match v.node.disr_expr { - Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id), + Some(ref expr) => tcx.hir().span(expr.hir_id), None => v.span }; struct_span_err!(tcx.sess, span, E0081, @@ -4363,7 +4363,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t for (&used, param) in types_used.iter().zip(types) { if !used { let id = tcx.hir().as_local_hir_id(param.def_id).unwrap(); - let span = tcx.hir().span_by_hir_id(id); + let span = tcx.hir().span(id); struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name) .span_label(span, "unused type parameter") .emit(); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index bf3381d206b5a..5c710399446ef 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -175,7 +175,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.err_count_since_creation() == 0 { // regionck assumes typeck succeeded - rcx.visit_fn_body(fn_id, body, self.tcx.hir().span_by_hir_id(fn_id)); + rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id)); } rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx)); diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index bf64643e5a745..034ff5f834767 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -70,7 +70,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> { /// the types first. pub fn check_item_well_formed<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let item = tcx.hir().expect_item(hir_id); debug!("check_item_well_formed(it.hir_id={:?}, it.name={})", item.hir_id, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index 1e33551b2560f..ffc323f28b675 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { wbcx.visit_node_id(arg.pat.span, arg.hir_id); } // Type only exists for constants and statics, not functions. - match self.tcx.hir().body_owner_kind_by_hir_id(item_id) { + match self.tcx.hir().body_owner_kind(item_id) { hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => { wbcx.visit_node_id(body.value.span, item_id); } @@ -398,7 +398,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { if let ty::UserType::TypeOf(_, user_substs) = c_ty.value { if self.rustc_dump_user_substs { // This is a unit-testing mechanism. - let span = self.tcx().hir().span_by_hir_id(hir_id); + let span = self.tcx().hir().span(hir_id); // We need to buffer the errors in order to guarantee a consistent // order when emitting them. let err = self.tcx().sess.struct_span_err( @@ -773,13 +773,13 @@ impl Locatable for Span { impl Locatable for DefIndex { fn to_span(&self, tcx: TyCtxt<'_>) -> Span { let hir_id = tcx.hir().def_index_to_hir_id(*self); - tcx.hir().span_by_hir_id(hir_id) + tcx.hir().span(hir_id) } } impl Locatable for hir::HirId { fn to_span(&self, tcx: TyCtxt<'_>) -> Span { - tcx.hir().span_by_hir_id(*self) + tcx.hir().span(*self) } } diff --git a/src/librustc_typeck/check_unused.rs b/src/librustc_typeck/check_unused.rs index c724500b9ede8..dda86778f2727 100644 --- a/src/librustc_typeck/check_unused.rs +++ b/src/librustc_typeck/check_unused.rs @@ -121,7 +121,7 @@ fn unused_crates_lint<'tcx>(tcx: TyCtxt<'tcx>) { for extern_crate in &crates_to_lint { let id = tcx.hir().as_local_hir_id(extern_crate.def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(id); + let item = tcx.hir().expect_item(id); // If the crate is fully unused, we suggest removing it altogether. // We do this in any edition. diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index a690eefdf1343..e392622060c9b 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -88,7 +88,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type); - let span = tcx.hir().span_by_hir_id(impl_hir_id); + let span = tcx.hir().span(impl_hir_id); let param_env = tcx.param_env(impl_did); assert!(!self_type.has_escaping_bound_vars()); @@ -98,7 +98,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { match param_env.can_type_implement_copy(tcx, self_type) { Ok(()) => {} Err(CopyImplementationError::InfrigingFields(fields)) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node { tr.path.span } else { @@ -115,7 +115,7 @@ fn visit_implementation_of_copy<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) { err.emit() } Err(CopyImplementationError::NotAnAdt) => { - let item = tcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = tcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., ref ty, _) = item.node { ty.span } else { @@ -161,7 +161,7 @@ fn visit_implementation_of_dispatch_from_dyn<'tcx>(tcx: TyCtxt<'tcx>, impl_did: let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap(); let impl_hir_id = tcx.hir().as_local_hir_id(impl_did).unwrap(); - let span = tcx.hir().span_by_hir_id(impl_hir_id); + let span = tcx.hir().span(impl_hir_id); let source = tcx.type_of(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -343,7 +343,7 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn source, target); - let span = gcx.hir().span_by_hir_id(impl_hir_id); + let span = gcx.hir().span(impl_hir_id); let param_env = gcx.param_env(impl_did); assert!(!source.has_escaping_bound_vars()); @@ -480,11 +480,11 @@ pub fn coerce_unsized_info<'tcx>(gcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn being coerced, none found"); return err_info; } else if diff_fields.len() > 1 { - let item = gcx.hir().expect_item_by_hir_id(impl_hir_id); + let item = gcx.hir().expect_item(impl_hir_id); let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node { t.path.span } else { - gcx.hir().span_by_hir_id(impl_hir_id) + gcx.hir().span(impl_hir_id) }; let mut err = struct_span_err!(gcx.sess, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1273fcfc2573c..5606d9c0ce815 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -742,7 +742,7 @@ fn super_predicates_of<'tcx>( fn trait_def<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx ty::TraitDef { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - let item = tcx.hir().expect_item_by_hir_id(hir_id); + let item = tcx.hir().expect_item(hir_id); let (is_auto, unsafety) = match item.node { hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety), @@ -1177,7 +1177,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), ImplItemKind::Existential(_) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1187,7 +1187,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op } ImplItemKind::Type(ref ty) => { if tcx - .impl_trait_ref(tcx.hir().get_parent_did_by_hir_id(hir_id)) + .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() { report_assoc_ty_on_inherent_impl(tcx, item.span); @@ -1272,7 +1272,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op .. }) => match *def { VariantData::Unit(..) | VariantData::Struct(..) => { - tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id)) + tcx.type_of(tcx.hir().get_parent_did(hir_id)) } VariantData::Tuple(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); @@ -1325,7 +1325,7 @@ pub fn checked_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, fail: bool) -> Op .. }) if e.hir_id == hir_id => { - tcx.adt_def(tcx.hir().get_parent_did_by_hir_id(hir_id)) + tcx.adt_def(tcx.hir().get_parent_did(hir_id)) .repr .discr_type() .to_ty(tcx) @@ -1709,7 +1709,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { node: ForeignItemKind::Fn(ref fn_decl, _, _), .. }) => { - let abi = tcx.hir().get_foreign_abi_by_hir_id(hir_id); + let abi = tcx.hir().get_foreign_abi(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id, fn_decl, abi) } @@ -1717,7 +1717,7 @@ fn fn_sig<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::PolyFnSig<'tcx> { node: hir::VariantKind { data, .. }, .. }) if data.ctor_hir_id().is_some() => { - let ty = tcx.type_of(tcx.hir().get_parent_did_by_hir_id(hir_id)); + let ty = tcx.type_of(tcx.hir().get_parent_did(hir_id)); let inputs = data.fields() .iter() .map(|f| tcx.type_of(tcx.hir().local_def_id_from_hir_id(f.hir_id))); @@ -1762,7 +1762,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option { opt_trait_ref.as_ref().map(|ast_trait_ref| { let selfty = tcx.type_of(def_id); @@ -1775,7 +1775,7 @@ fn impl_trait_ref<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option(tcx: TyCtxt<'tcx>, def_id: DefId) -> hir::ImplPolarity { let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(_, polarity, ..) => polarity, ref item => bug!("impl_polarity: {:?} not an impl", item), } diff --git a/src/librustc_typeck/variance/mod.rs b/src/librustc_typeck/variance/mod.rs index ea458842acce6..5dbd667485e98 100644 --- a/src/librustc_typeck/variance/mod.rs +++ b/src/librustc_typeck/variance/mod.rs @@ -46,7 +46,7 @@ fn variances_of<'tcx>(tcx: TyCtxt<'tcx>, item_def_id: DefId) -> &'tcx [ty::Varia let id = tcx.hir().as_local_hir_id(item_def_id).expect("expected local def-id"); let unsupported = || { // Variance not relevant. - span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item") + span_bug!(tcx.hir().span(id), "asked to compute variance for wrong kind of item") }; match tcx.hir().get_by_hir_id(id) { Node::Item(item) => match item.node { diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 5a5540e7e3855..c14ae5932af47 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -305,7 +305,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec) { } let for_ = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(.., ref t, _) => { t.clean(cx) } @@ -327,7 +327,7 @@ pub fn build_impl(cx: &DocContext<'_>, did: DefId, ret: &mut Vec) { let predicates = tcx.explicit_predicates_of(did); let (trait_items, generics) = if let Some(hir_id) = tcx.hir().as_local_hir_id(did) { - match tcx.hir().expect_item_by_hir_id(hir_id).node { + match tcx.hir().expect_item(hir_id).node { hir::ItemKind::Impl(.., ref gen, _, _, ref item_ids) => { ( item_ids.iter() diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 43cb3dd7261c8..4becb42d30551 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -276,7 +276,7 @@ impl Clean for CrateNum { }; let primitives = if root.is_local() { cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| { - let item = cx.tcx.hir().expect_item_by_hir_id(id.id); + let item = cx.tcx.hir().expect_item(id.id); match item.node { hir::ItemKind::Mod(_) => { as_primitive(Res::Def( @@ -320,7 +320,7 @@ impl Clean for CrateNum { }; let keywords = if root.is_local() { cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| { - let item = cx.tcx.hir().expect_item_by_hir_id(id.id); + let item = cx.tcx.hir().expect_item(id.id); match item.node { hir::ItemKind::Mod(_) => { as_keyword(Res::Def( @@ -2777,7 +2777,7 @@ impl Clean for hir::Ty { }, TyKind::Tup(ref tys) => Tuple(tys.clean(cx)), TyKind::Def(item_id, _) => { - let item = cx.tcx.hir().expect_item_by_hir_id(item_id.id); + let item = cx.tcx.hir().expect_item(item_id.id); if let hir::ItemKind::Existential(ref ty) = item.node { ImplTrait(ty.bounds.clean(cx)) } else { @@ -2799,7 +2799,7 @@ impl Clean for hir::Ty { // Substitute private type aliases if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(def_id) { if !cx.renderinfo.borrow().access_levels.is_exported(def_id) { - alias = Some(&cx.tcx.hir().expect_item_by_hir_id(hir_id).node); + alias = Some(&cx.tcx.hir().expect_item(hir_id).node); } } }; @@ -4441,7 +4441,7 @@ pub fn path_to_def_local(tcx: TyCtxt<'_>, path: &[Symbol]) -> Option { let segment = path_it.next()?; for item_id in mem::replace(&mut items, HirVec::new()).iter() { - let item = tcx.hir().expect_item_by_hir_id(item_id.id); + let item = tcx.hir().expect_item(item_id.id); if item.ident.name == *segment { if path_it.peek().is_none() { return Some(tcx.hir().local_def_id_from_hir_id(item_id.id)) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index eb9de43e38861..ff76579d67d21 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -248,7 +248,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { let orig_inside_public_path = self.inside_public_path; self.inside_public_path &= vis.node.is_pub(); for i in &m.item_ids { - let item = self.cx.tcx.hir().expect_item_by_hir_id(i.id); + let item = self.cx.tcx.hir().expect_item(i.id); self.visit_item(item, None, &mut om); } self.inside_public_path = orig_inside_public_path; @@ -275,7 +275,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool { while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) { node = id; - if cx.tcx.hir().attrs_by_hir_id(node) + if cx.tcx.hir().attrs(node) .lists(sym::doc).has_word(sym::hidden) { return true; } @@ -295,7 +295,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { return false; }; - let use_attrs = tcx.hir().attrs_by_hir_id(id); + let use_attrs = tcx.hir().attrs(id); // Don't inline `doc(hidden)` imports so they can be stripped at a later stage. let is_no_inline = use_attrs.lists(sym::doc).has_word(sym::no_inline) || use_attrs.lists(sym::doc).has_word(sym::hidden); @@ -346,7 +346,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { Node::Item(&hir::Item { node: hir::ItemKind::Mod(ref m), .. }) if glob => { let prev = mem::replace(&mut self.inlining, true); for i in &m.item_ids { - let i = self.cx.tcx.hir().expect_item_by_hir_id(i.id); + let i = self.cx.tcx.hir().expect_item(i.id); self.visit_item(i, None, om); } self.inlining = prev; @@ -361,7 +361,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { Node::ForeignItem(it) if !glob => { // Generate a fresh `extern {}` block if we want to inline a foreign item. om.foreigns.push(hir::ForeignMod { - abi: tcx.hir().get_foreign_abi_by_hir_id(it.hir_id), + abi: tcx.hir().get_foreign_abi(it.hir_id), items: vec![hir::ForeignItem { ident: renamed.unwrap_or(it.ident), .. it.clone() diff --git a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs index 40e0115c623ee..76554eaba9c92 100644 --- a/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs +++ b/src/test/run-pass-fulldeps/auxiliary/issue-40001-plugin.rs @@ -45,7 +45,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass { let item = match cx.tcx.hir().get_by_hir_id(id) { Node::Item(item) => item, - _ => cx.tcx.hir().expect_item_by_hir_id(cx.tcx.hir().get_parent_item(id)), + _ => cx.tcx.hir().expect_item(cx.tcx.hir().get_parent_item(id)), }; if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) { From 1c8551b0ebb4efc72dd1d57035672e5b1c915ac2 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:30:02 +0200 Subject: [PATCH 3/8] renamve hir_to_string to node_to_string --- src/librustc/cfg/graphviz.rs | 2 +- src/librustc/hir/map/hir_id_validator.rs | 8 +++---- src/librustc/hir/map/mod.rs | 28 +++++++++++------------ src/librustc/infer/opaque_types/mod.rs | 2 +- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/reachable.rs | 2 +- src/librustc/middle/resolve_lifetime.rs | 2 +- src/librustc/ty/context.rs | 4 ++-- src/librustc_borrowck/borrowck/mod.rs | 6 ++--- src/librustc_typeck/check/mod.rs | 4 ++-- src/librustc_typeck/coherence/orphan.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- 12 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/librustc/cfg/graphviz.rs b/src/librustc/cfg/graphviz.rs index 0bfb6b98e630b..66963e5856eec 100644 --- a/src/librustc/cfg/graphviz.rs +++ b/src/librustc/cfg/graphviz.rs @@ -26,7 +26,7 @@ impl<'a, 'tcx> LabelledCFG<'a, 'tcx> { owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner, local_id }; - let s = self.tcx.hir().hir_to_string(hir_id); + let s = self.tcx.hir().node_to_string(hir_id); // Replacing newlines with \\l causes each line to be left-aligned, // improving presentation of (long) pretty-printed expressions. diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 08ec2aeed2905..d6ac7ea2ed703 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -125,7 +125,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, - self.hir_map.hir_to_string(hir_id))); + self.hir_map.node_to_string(hir_id))); } self.error(|| format!( "ItemLocalIds not assigned densely in {}. \ @@ -139,7 +139,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { owner: owner_def_index, local_id, }) - .map(|h| format!("({:?} {})", h, self.hir_map.hir_to_string(h))) + .map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h))) .collect::>())); } } @@ -157,14 +157,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> { if hir_id == hir::DUMMY_HIR_ID { self.error(|| format!("HirIdValidator: HirId {:?} is invalid", - self.hir_map.hir_to_string(hir_id))); + self.hir_map.node_to_string(hir_id))); return; } if owner != hir_id.owner { self.error(|| format!( "HirIdValidator: The recorded owner of {} is {} instead of {}", - self.hir_map.hir_to_string(hir_id), + self.hir_map.node_to_string(hir_id), self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(), self.hir_map.def_path(DefId::local(owner)).to_string_no_crate())); } diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5a45f04b63719..26c08154647e2 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -453,7 +453,7 @@ impl<'hir> Map<'hir> { pub fn body_owned_by(&self, id: HirId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { span_bug!(self.span(id), "body_owned_by: {} has no associated body", - self.hir_to_string(id)); + self.node_to_string(id)); }) } @@ -486,7 +486,7 @@ impl<'hir> Map<'hir> { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => id, Node::GenericParam(_) => self.get_parent_node_by_hir_id(id), - _ => bug!("ty_param_owner: {} not a type parameter", self.hir_to_string(id)) + _ => bug!("ty_param_owner: {} not a type parameter", self.node_to_string(id)) } } @@ -495,7 +495,7 @@ impl<'hir> Map<'hir> { Node::Item(&Item { node: ItemKind::Trait(..), .. }) | Node::Item(&Item { node: ItemKind::TraitAlias(..), .. }) => kw::SelfUpper, Node::GenericParam(param) => param.name.ident().name, - _ => bug!("ty_param_name: {} not a type parameter", self.hir_to_string(id)), + _ => bug!("ty_param_name: {} not a type parameter", self.node_to_string(id)), } } @@ -874,27 +874,27 @@ impl<'hir> Map<'hir> { return nm.abi; } } - bug!("expected foreign mod or inlined parent, found {}", self.hir_to_string(parent)) + bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent)) } pub fn expect_item(&self, id: HirId) -> &'hir Item { match self.find_by_hir_id(id) { // read recorded by `find` Some(Node::Item(item)) => item, - _ => bug!("expected item, found {}", self.hir_to_string(id)) + _ => bug!("expected item, found {}", self.node_to_string(id)) } } pub fn expect_impl_item(&self, id: HirId) -> &'hir ImplItem { match self.find_by_hir_id(id) { Some(Node::ImplItem(item)) => item, - _ => bug!("expected impl item, found {}", self.hir_to_string(id)) + _ => bug!("expected impl item, found {}", self.node_to_string(id)) } } pub fn expect_trait_item(&self, id: HirId) -> &'hir TraitItem { match self.find_by_hir_id(id) { Some(Node::TraitItem(item)) => item, - _ => bug!("expected trait item, found {}", self.hir_to_string(id)) + _ => bug!("expected trait item, found {}", self.node_to_string(id)) } } @@ -904,26 +904,26 @@ impl<'hir> Map<'hir> { match i.node { ItemKind::Struct(ref struct_def, _) | ItemKind::Union(ref struct_def, _) => struct_def, - _ => bug!("struct ID bound to non-struct {}", self.hir_to_string(id)) + _ => bug!("struct ID bound to non-struct {}", self.node_to_string(id)) } } Some(Node::Variant(variant)) => &variant.node.data, Some(Node::Ctor(data)) => data, - _ => bug!("expected struct or variant, found {}", self.hir_to_string(id)) + _ => bug!("expected struct or variant, found {}", self.node_to_string(id)) } } pub fn expect_variant(&self, id: HirId) -> &'hir Variant { match self.find_by_hir_id(id) { Some(Node::Variant(variant)) => variant, - _ => bug!("expected variant, found {}", self.hir_to_string(id)), + _ => bug!("expected variant, found {}", self.node_to_string(id)), } } pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem { match self.find_by_hir_id(id) { Some(Node::ForeignItem(item)) => item, - _ => bug!("expected foreign item, found {}", self.hir_to_string(id)) + _ => bug!("expected foreign item, found {}", self.node_to_string(id)) } } @@ -936,7 +936,7 @@ impl<'hir> Map<'hir> { pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { match self.find_by_hir_id(id) { // read recorded by find Some(Node::Expr(expr)) => expr, - _ => bug!("expected expr, found {}", self.hir_to_string(id)) + _ => bug!("expected expr, found {}", self.node_to_string(id)) } } @@ -959,7 +959,7 @@ impl<'hir> Map<'hir> { Node::GenericParam(param) => param.name.ident().name, Node::Binding(&Pat { node: PatKind::Binding(_, _, l, _), .. }) => l.name, Node::Ctor(..) => self.name_by_hir_id(self.get_parent_item(id)), - _ => bug!("no name for {}", self.hir_to_string(id)) + _ => bug!("no name for {}", self.node_to_string(id)) } } @@ -1071,7 +1071,7 @@ impl<'hir> Map<'hir> { self.as_local_hir_id(id).map(|id| self.span(id)) } - pub fn hir_to_string(&self, id: HirId) -> String { + pub fn node_to_string(&self, id: HirId) -> String { hir_id_to_string(self, id, true) } diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 1c52b5775a0cc..328ace51a5828 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -819,7 +819,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { }, _ => bug!( "expected (impl) item, found {}", - tcx.hir().hir_to_string(opaque_hir_id), + tcx.hir().node_to_string(opaque_hir_id), ), }; if in_definition_scope { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index a856430e68a23..192e72383acee 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -501,7 +501,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { None if self.is_tainted_by_errors() => Err(()), None => { bug!("no type for node {}: {} in mem_categorization", - id, self.tcx.hir().hir_to_string(id)); + id, self.tcx.hir().node_to_string(id)); } } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 2285beb375859..628a44cbfe01f 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -318,7 +318,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { _ => { bug!( "found unexpected node kind in worklist: {} ({:?})", - self.tcx.hir().hir_to_string(search_item), + self.tcx.hir().node_to_string(search_item), node, ); } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 6f2c4b66f5ec4..76bff500634a9 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -2696,7 +2696,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!( "insert_lifetime: {} resolved to {:?} span={:?}", - self.tcx.hir().hir_to_string(lifetime_ref.hir_id), + self.tcx.hir().node_to_string(lifetime_ref.hir_id), def, self.tcx.sess.source_map().span_to_string(lifetime_ref.span) ); diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index c32f62e88c423..b84ebd8afe885 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -252,7 +252,7 @@ fn validate_hir_id_for_typeck_tables(local_id_root: Option, ty::tls::with(|tcx| { bug!("node {} with HirId::owner {:?} cannot be placed in \ TypeckTables with local_id_root {:?}", - tcx.hir().hir_to_string(hir_id), + tcx.hir().node_to_string(hir_id), DefId::local(hir_id.owner), local_id_root) }); @@ -554,7 +554,7 @@ impl<'tcx> TypeckTables<'tcx> { pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> { self.node_type_opt(id).unwrap_or_else(|| bug!("node_type: no type for node `{}`", - tls::with(|tcx| tcx.hir().hir_to_string(id))) + tls::with(|tcx| tcx.hir().node_to_string(id))) ) } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index cc9c83de179c8..23b28952935d1 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1508,12 +1508,12 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.kind { LpVar(id) => { - write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().hir_to_string(id))) + write!(f, "$({})", ty::tls::with(|tcx| tcx.hir().node_to_string(id))) } LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath {hir_id: var_id}, closure_expr_id }) => { let s = ty::tls::with(|tcx| { - tcx.hir().hir_to_string(var_id) + tcx.hir().node_to_string(var_id) }); write!(f, "$({} captured by id={:?})", s, closure_expr_id) } @@ -1547,7 +1547,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> { LpUpvar(ty::UpvarId{ var_path: ty::UpvarPath { hir_id }, closure_expr_id: _ }) => { let s = ty::tls::with(|tcx| { - tcx.hir().hir_to_string(hir_id) + tcx.hir().node_to_string(hir_id) }); write!(f, "$({} captured by closure)", s) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d4dbb68778ed2..10bfe9e034d32 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2181,7 +2181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn local_ty(&self, span: Span, nid: hir::HirId) -> LocalTy<'tcx> { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| span_bug!(span, "no type for local variable {}", - self.tcx.hir().hir_to_string(nid)) + self.tcx.hir().node_to_string(nid)) ) } @@ -2518,7 +2518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { None if self.is_tainted_by_errors() => self.tcx.types.err, None => { bug!("no type for node {}: {} in fcx {}", - id, self.tcx.hir().hir_to_string(id), + id, self.tcx.hir().node_to_string(id), self.tag()); } } diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 43063d7b8d12a..4e6fcfe0593e2 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -26,7 +26,7 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> { // "Trait" impl if let hir::ItemKind::Impl(.., Some(_), _, _) = item.node { debug!("coherence2::orphan check: trait impl {}", - self.tcx.hir().hir_to_string(item.hir_id)); + self.tcx.hir().node_to_string(item.hir_id)); let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap(); let trait_def_id = trait_ref.def_id; let cm = self.tcx.sess.source_map(); diff --git a/src/librustc_typeck/variance/terms.rs b/src/librustc_typeck/variance/terms.rs index b120f995ad3a6..99f87ccb6f65e 100644 --- a/src/librustc_typeck/variance/terms.rs +++ b/src/librustc_typeck/variance/terms.rs @@ -129,7 +129,7 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> { impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { debug!("add_inferreds for item {}", - self.tcx.hir().hir_to_string(item.hir_id)); + self.tcx.hir().node_to_string(item.hir_id)); match item.node { hir::ItemKind::Struct(ref struct_def, _) | From 21fbb59500ec50bab7e8a2b00af8a00c967f6b76 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:30:53 +0200 Subject: [PATCH 4/8] fix a HIR doc, simplify one HIR-related function call --- src/librustc/cfg/construct.rs | 3 +-- src/librustc/hir/map/mod.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 8f0f832b6c418..85602320f0b0d 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -42,8 +42,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG { let body_exit; // Find the tables for this body. - let owner_hir_id = tcx.hir().body_owner(body.id()); - let owner_def_id = tcx.hir().local_def_id_from_hir_id(owner_hir_id); + let owner_def_id = tcx.hir().body_owner_def_id(body.id()); let tables = tcx.typeck_tables_of(owner_def_id); let mut cfg_builder = CFGBuilder { diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 26c08154647e2..18b8d23a455c9 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -420,7 +420,7 @@ impl<'hir> Map<'hir> { } } - /// Returns the `NodeId` that corresponds to the definition of + /// Returns the `HirId` that corresponds to the definition of /// which this is the body of, i.e., a `fn`, `const` or `static` /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> HirId { From 88961b049ec2e8dec3f7b1c8166fb201c0632bbe Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:37:58 +0200 Subject: [PATCH 5/8] simplify ICE handling in HirIdValidator --- src/librustc/hir/map/hir_id_validator.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index d6ac7ea2ed703..32d0e069f72de 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -1,6 +1,5 @@ use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX}; use crate::hir::{self, intravisit, HirId, ItemLocalId}; -use syntax::ast::NodeId; use crate::hir::itemlikevisit::ItemLikeVisitor; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter}; @@ -112,17 +111,6 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { trace!("missing hir id {:#?}", hir_id); - // We are already in ICE mode here, so doing a linear search - // should be fine. - let (node_id, _) = self.hir_map - .definitions() - .node_to_hir_id - .iter() - .enumerate() - .find(|&(_, &entry)| hir_id == entry) - .expect("no node_to_hir_id entry"); - let node_id = NodeId::from_usize(node_id); - let hir_id = self.hir_map.node_to_hir_id(node_id); missing_items.push(format!("[local_id: {}, node:{}]", local_id, self.hir_map.node_to_string(hir_id))); From 72bb5c7067a12aa28a32c377135a1dd34bb73cb7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 16 Jun 2019 17:44:19 +0200 Subject: [PATCH 6/8] change NodeId to HirId in some HIR docs --- src/librustc/hir/map/mod.rs | 10 +++++----- src/librustc/hir/mod.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 18b8d23a455c9..85c86991f489a 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -35,7 +35,7 @@ mod def_collector; pub mod definitions; mod hir_id_validator; -/// Represents an entry and its parent `NodeId`. +/// Represents an entry and its parent `HirId`. #[derive(Copy, Clone, Debug)] pub struct Entry<'hir> { parent: HirId, @@ -200,7 +200,7 @@ impl<'hir> Map<'hir> { /// "reveals" the content of a node to the caller (who might not /// otherwise have had access to those contents, and hence needs a /// read recorded). If the function just returns a DefId or - /// NodeId, no actual content was returned, so no read is needed. + /// HirId, no actual content was returned, so no read is needed. pub fn read(&self, hir_id: HirId) { if let Some(entry) = self.lookup(hir_id) { self.dep_graph.read_index(entry.dep_node); @@ -681,7 +681,7 @@ impl<'hir> Map<'hir> { /// If there is some error when walking the parents (e.g., a node does not /// have a parent in the map or a node can't be found), then we return the - /// last good `NodeId` we found. Note that reaching the crate root (`id == 0`), + /// last good `HirId` we found. Note that reaching the crate root (`id == 0`), /// is not an error, since items in the crate module have the crate root as /// parent. fn walk_parent_nodes(&self, @@ -717,7 +717,7 @@ impl<'hir> Map<'hir> { } } - /// Retrieves the `NodeId` for `id`'s enclosing method, unless there's a + /// Retrieves the `HirId` for `id`'s enclosing method, unless there's a /// `while` or `loop` before reaching it, as block tail returns are not /// available in them. /// @@ -725,7 +725,7 @@ impl<'hir> Map<'hir> { /// fn foo(x: usize) -> bool { /// if x == 1 { /// true // `get_return_block` gets passed the `id` corresponding - /// } else { // to this, it will return `foo`'s `NodeId`. + /// } else { // to this, it will return `foo`'s `HirId`. /// false /// } /// } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 6ace4c4174b56..0884a726a27b0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -2177,8 +2177,8 @@ pub enum UseKind { /// References to traits in impls. /// /// `resolve` maps each `TraitRef`'s `ref_id` to its defining trait; that's all -/// that the `ref_id` is for. Note that `ref_id`'s value is not the `NodeId` of the -/// trait being referred to but just a unique `NodeId` that serves as a key +/// that the `ref_id` is for. Note that `ref_id`'s value is not the `HirId` of the +/// trait being referred to but just a unique `HirId` that serves as a key /// within the resolution map. #[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct TraitRef { From 61e004d68e916694c12fb9051826ed1779ac98d6 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 17 Jun 2019 19:01:41 +0200 Subject: [PATCH 7/8] fix rebase fallout --- src/librustc_typeck/check/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index fa9e0d8a8578a..421688097b892 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -180,7 +180,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.diverges.set(self.diverges.get() | old_diverges); self.has_errors.set(self.has_errors.get() | old_has_errors); - debug!("type of {} is...", self.tcx.hir().hir_to_string(expr.hir_id)); + debug!("type of {} is...", self.tcx.hir().node_to_string(expr.hir_id)); debug!("... {:?}, expected is {:?}", ty, expected); ty From e1bf56de25a78b3883822f82aeba0010c4a2fad7 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 17 Jun 2019 20:31:26 +0200 Subject: [PATCH 8/8] remove superfluous space --- src/librustc_borrowck/borrowck/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 23b28952935d1..93cea6d2f019f 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -896,7 +896,7 @@ impl BorrowckCtxt<'_, 'tcx> { // to implement two traits for "one operator" is not very intuitive for // many programmers. if err.cmt.note == mc::NoteIndex { - let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); + let node = self.tcx.hir().get_by_hir_id(err.cmt.hir_id); // This pattern probably always matches. if let Node::Expr(