diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 949fdd2682b96..7715e926aa1f5 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -89,8 +89,7 @@ pub struct LoweringContext<'a> { bodies: BTreeMap, exported_macros: Vec, - trait_impls: BTreeMap>, - trait_auto_impl: BTreeMap, + trait_impls: BTreeMap>, modules: BTreeMap, @@ -233,7 +232,6 @@ pub fn lower_crate( impl_items: BTreeMap::new(), bodies: BTreeMap::new(), trait_impls: BTreeMap::new(), - trait_auto_impl: BTreeMap::new(), modules: BTreeMap::new(), exported_macros: Vec::new(), catch_scopes: Vec::new(), @@ -514,7 +512,6 @@ impl<'a> LoweringContext<'a> { bodies: self.bodies, body_ids, trait_impls: self.trait_impls, - trait_auto_impl: self.trait_auto_impl, modules: self.modules, } } @@ -2967,6 +2964,7 @@ impl<'a> LoweringContext<'a> { // method, it will not be considered an in-band // lifetime to be added, but rather a reference to a // parent lifetime. + let lowered_trait_impl_id = self.lower_node_id(id).hir_id; let (generics, (trait_ref, lowered_ty)) = self.add_in_band_defs( ast_generics, def_id, @@ -2978,7 +2976,8 @@ impl<'a> LoweringContext<'a> { if let Some(ref trait_ref) = trait_ref { if let Def::Trait(def_id) = trait_ref.path.def { - this.trait_impls.entry(def_id).or_default().push(id); + this.trait_impls.entry(def_id).or_default().push( + lowered_trait_impl_id); } } diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 9f39d648df1bf..e88f9e60702f7 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -121,7 +121,6 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> { impl_items: _, bodies: _, trait_impls: _, - trait_auto_impl: _, body_ids: _, modules: _, } = *krate; diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 86b6805cc9b4c..19b9c78be4c38 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -555,7 +555,7 @@ impl<'hir> Map<'hir> { } } - pub fn trait_impls(&self, trait_did: DefId) -> &'hir [NodeId] { + pub fn trait_impls(&self, trait_did: DefId) -> &'hir [HirId] { self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls)); // N.B., intentionally bypass `self.forest.krate()` so that we @@ -563,18 +563,6 @@ impl<'hir> Map<'hir> { self.forest.krate.trait_impls.get(&trait_did).map_or(&[], |xs| &xs[..]) } - pub fn trait_auto_impl(&self, trait_did: DefId) -> Option { - self.dep_graph.read(DepNode::new_no_params(DepKind::AllLocalTraitImpls)); - - // N.B., intentionally bypass `self.forest.krate()` so that we - // do not trigger a read of the whole krate here - self.forest.krate.trait_auto_impl.get(&trait_did).cloned() - } - - pub fn trait_is_auto(&self, trait_did: DefId) -> bool { - self.trait_auto_impl(trait_did).is_some() - } - /// Gets the attributes on the crate. This is preferable to /// invoking `krate.attrs` because it registers a tighter /// dep-graph access. diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index e47bc3d1c2533..a099811b748b1 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -723,8 +723,7 @@ pub struct Crate { pub trait_items: BTreeMap, pub impl_items: BTreeMap, pub bodies: BTreeMap, - pub trait_impls: BTreeMap>, - pub trait_auto_impl: BTreeMap, + pub trait_impls: BTreeMap>, /// A list of the body ids written out in the order in which they /// appear in the crate. If you're going to process all the bodies diff --git a/src/librustc/ty/trait_def.rs b/src/librustc/ty/trait_def.rs index 9ce8bf2e60a31..a45b5b5b8470a 100644 --- a/src/librustc/ty/trait_def.rs +++ b/src/librustc/ty/trait_def.rs @@ -179,8 +179,8 @@ pub(super) fn trait_impls_of_provider<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - for &node_id in tcx.hir().trait_impls(trait_id) { - add_impl(tcx.hir().local_def_id(node_id)); + for &hir_id in tcx.hir().trait_impls(trait_id) { + add_impl(tcx.hir().local_def_id_from_hir_id(hir_id)); } } diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 0e08b62668ac8..9680dd4ce2faf 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -2,13 +2,13 @@ //! does not exceed the lifetime of the value being borrowed. use crate::borrowck::*; +use rustc::hir::HirId; use rustc::middle::expr_use_visitor as euv; use rustc::middle::mem_categorization as mc; use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty; -use syntax::ast; use syntax_pos::Span; use log::debug; @@ -51,7 +51,7 @@ struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { } impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { - fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option) -> R { + fn check(&self, cmt: &mc::cmt_<'tcx>, discr_scope: Option) -> R { //! Main routine. Walks down `cmt` until we find the //! "guarantor". Reports an error if `self.loan_region` is //! larger than scope of `cmt`. diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index bf730ba41f428..ed631f2cdaa0d 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -14,7 +14,6 @@ use rustc::middle::mem_categorization::Categorization; use rustc::middle::region; use rustc::ty::{self, TyCtxt}; -use syntax::ast; use syntax_pos::Span; use rustc::hir; use log::debug; @@ -141,8 +140,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { assignee_cmt: &mc::cmt_<'tcx>, _: euv::MutateMode) { - let node_id = self.bccx.tcx.hir().hir_to_node_id(assignment_id); - self.guarantee_assignment_valid(node_id, + self.guarantee_assignment_valid(assignment_id, assignment_span, assignee_cmt); } @@ -238,7 +236,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { /// Guarantees that `cmt` is assignable, or reports an error. fn guarantee_assignment_valid(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, cmt: &mc::cmt_<'tcx>) { @@ -272,8 +270,7 @@ impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { self.mark_loan_path_as_mutated(&lp); } gather_moves::gather_assignment(self.bccx, &self.move_data, - self.bccx.tcx.hir().node_to_hir_id(assignment_id) - .local_id, + assignment_id.local_id, assignment_span, lp); } diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index da065f9e05d9e..3a6e53a92482c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -34,7 +34,6 @@ use std::fmt; use std::rc::Rc; use rustc_data_structures::sync::Lrc; use std::hash::{Hash, Hasher}; -use syntax::ast; use syntax_pos::{MultiSpan, Span}; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; use log::debug; @@ -399,12 +398,12 @@ pub enum LoanPathElem<'tcx> { } fn closure_to_block(closure_id: LocalDefId, - tcx: TyCtxt<'_, '_, '_>) -> ast::NodeId { + tcx: TyCtxt<'_, '_, '_>) -> HirId { let closure_id = tcx.hir().local_def_id_to_node_id(closure_id); match tcx.hir().get(closure_id) { Node::Expr(expr) => match expr.node { hir::ExprKind::Closure(.., body_id, _, _) => { - tcx.hir().hir_to_node_id(body_id.hir_id) + body_id.hir_id } _ => { bug!("encountered non-closure id: {}", closure_id) @@ -422,8 +421,7 @@ impl<'a, 'tcx> LoanPath<'tcx> { } LpUpvar(upvar_id) => { let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx); - let hir_id = bccx.tcx.hir().node_to_hir_id(block_id); - region::Scope { id: hir_id.local_id, data: region::ScopeData::Node } + region::Scope { id: block_id.local_id, data: region::ScopeData::Node } } LpDowncast(ref base, _) | LpExtend(ref base, ..) => base.kill_scope(bccx), diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index 4d9a3775b3123..ae8dfa8144fd9 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -23,7 +23,6 @@ use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc_errors::DiagnosticBuilder; use std::iter; -use syntax::ast; use super::ToRegionVid; @@ -200,12 +199,10 @@ impl<'tcx> UniversalRegions<'tcx> { param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; - let mir_node_id = tcx.hir().as_local_node_id(mir_def_id).unwrap(); - let mir_hir_id = tcx.hir().node_to_hir_id(mir_node_id); + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id).unwrap(); UniversalRegionsBuilder { infcx, mir_def_id, - mir_node_id, mir_hir_id, param_env, }.build() @@ -370,7 +367,6 @@ struct UniversalRegionsBuilder<'cx, 'gcx: 'tcx, 'tcx: 'cx> { infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>, mir_def_id: DefId, mir_hir_id: HirId, - mir_node_id: ast::NodeId, param_env: ty::ParamEnv<'tcx>, } @@ -475,7 +471,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, '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(self.mir_node_id) { + match tcx.hir().body_owner_kind_by_hir_id(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 c8e48dea1f34c..3aac79c1d16ad 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -373,7 +373,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// finish building it. guard_context: Vec, - /// Maps `NodeId`s of variable bindings to the `Local`s created for them. + /// Maps `HirId`s of variable bindings to the `Local`s created for them. /// (A match binding can have two locals; the 2nd is for the arm's guard.) var_indices: HirIdMap, local_decls: IndexVec>, @@ -451,7 +451,7 @@ impl BlockContext { #[derive(Debug)] enum LocalsForNode { - /// In the usual case, a `NodeId` for an identifier maps to at most + /// In the usual case, a `HirId` for an identifier maps to at most /// one `Local` declaration. One(Local), diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 8f27b5b7dc81f..5e3ebcb3446c6 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -196,7 +196,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { )?; if let Some(import_id) = pick.import_id { - let import_def_id = self.tcx.hir().local_def_id(import_id); + let import_def_id = self.tcx.hir().local_def_id_from_hir_id(import_id); debug!("used_trait_import: {:?}", import_def_id); Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) .unwrap().insert(import_def_id); @@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self_ty, expr_id, ProbeScope::TraitsInScope)?; debug!("resolve_ufcs: pick={:?}", pick); if let Some(import_id) = pick.import_id { - let import_def_id = tcx.hir().local_def_id(import_id); + let import_def_id = tcx.hir().local_def_id_from_hir_id(import_id); debug!("resolve_ufcs: used_trait_import: {:?}", import_def_id); Lrc::get_mut(&mut self.tables.borrow_mut().used_trait_imports) .unwrap().insert(import_def_id); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index efae870c3c3a9..217be19e72a0c 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -120,7 +120,7 @@ struct Candidate<'tcx> { xform_ret_ty: Option>, item: ty::AssociatedItem, kind: CandidateKind<'tcx>, - import_id: Option, + import_id: Option, } #[derive(Debug)] @@ -145,7 +145,7 @@ enum ProbeResult { pub struct Pick<'tcx> { pub item: ty::AssociatedItem, pub kind: PickKind<'tcx>, - pub import_id: Option, + pub import_id: Option, // Indicates that the source expression should be autoderef'd N times // @@ -836,7 +836,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { for trait_candidate in applicable_traits.iter() { let trait_did = trait_candidate.def_id; if duplicates.insert(trait_did) { - let import_id = trait_candidate.import_id; + let import_id = trait_candidate.import_id.map(|node_id| + self.fcx.tcx.hir().node_to_hir_id(node_id)); let result = self.assemble_extension_candidates_for_trait(import_id, trait_did); result?; } @@ -887,7 +888,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } fn assemble_extension_candidates_for_trait(&mut self, - import_id: Option, + import_id: Option, trait_def_id: DefId) -> Result<(), MethodError<'tcx>> { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 28c79ce0c74e8..13f17d2f44fb1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4966,10 +4966,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // that highlight errors inline. let mut sp = blk.span; let mut fn_span = None; - let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id); - if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) { + if let Some((decl, ident)) = self.get_parent_fn_decl(blk.hir_id) { let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk_node_id) { + if let Some(block_sp) = self.parent_item_span(blk.hir_id) { // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the // output would otherwise be incorrect and even misleading. Make sure // the span we're aiming at correspond to a `fn` body. @@ -5009,8 +5008,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty } - fn parent_item_span(&self, id: ast::NodeId) -> Option { - let node = self.tcx.hir().get(self.tcx.hir().get_parent(id)); + fn parent_item_span(&self, id: hir::HirId) -> Option { + let node = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(id)); match node { Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, _, _, body_id), .. @@ -5028,9 +5027,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None } - /// Given a function block's `NodeId`, returns its `FnDecl` if it exists, or `None` otherwise. - fn get_parent_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, ast::Ident)> { - let parent = self.tcx.hir().get(self.tcx.hir().get_parent(blk_id)); + /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. + fn get_parent_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, ast::Ident)> { + let parent = self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_item(blk_id)); self.get_node_fn_decl(parent).map(|(fn_decl, ident, _)| (fn_decl, ident)) } diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index d001545d1d915..01a77e85caede 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -15,7 +15,6 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::util::nodemap::DefIdSet; use rustc_data_structures::sync::Lrc; use std::mem; -use syntax::ast; use syntax_pos::Span; /////////////////////////////////////////////////////////////////////////// @@ -444,8 +443,8 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { fn visit_opaque_types(&mut self, span: Span) { for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() { - let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap(); - let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id); + let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap(); + let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id); let generics = self.tcx().generics_of(def_id); @@ -731,12 +730,6 @@ impl Locatable for Span { } } -impl Locatable for ast::NodeId { - fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span { - tcx.hir().span(*self) - } -} - impl Locatable for DefIndex { fn to_span(&self, tcx: &TyCtxt<'_, '_, '_>) -> Span { let hir_id = tcx.hir().def_index_to_hir_id(*self); diff --git a/src/librustc_typeck/coherence/builtin.rs b/src/librustc_typeck/coherence/builtin.rs index 5d86bc5409532..2cb2dd50d7505 100644 --- a/src/librustc_typeck/coherence/builtin.rs +++ b/src/librustc_typeck/coherence/builtin.rs @@ -37,7 +37,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { { if Some(self.trait_def_id) == trait_def_id { for &impl_id in self.tcx.hir().trait_impls(self.trait_def_id) { - let impl_def_id = self.tcx.hir().local_def_id(impl_id); + let impl_def_id = self.tcx.hir().local_def_id_from_hir_id(impl_id); f(self.tcx, impl_def_id); } } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 39a2f5d37bd7a..bf7284d8445ff 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -5,22 +5,21 @@ // done by the orphan and overlap modules. Then we build up various // mappings. That mapping code resides here. +use crate::hir::HirId; use crate::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::traits; use rustc::ty::{self, TyCtxt, TypeFoldable}; use rustc::ty::query::Providers; use rustc::util::common::time; -use syntax::ast; - mod builtin; mod inherent_impls; mod inherent_impls_overlap; mod orphan; mod unsafety; -fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { - let impl_def_id = tcx.hir().local_def_id(node_id); +fn check_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_id: HirId) { + let impl_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); // If there are no traits, then this implementation must have a // base type. @@ -160,8 +159,8 @@ pub fn check_coherence<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { /// Overlap: no two impls for the same trait are implemented for the /// same type. Likewise, no two inherent impls for a given type /// constructor provide a method with the same name. -fn check_impl_overlap<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, node_id: ast::NodeId) { - let impl_def_id = tcx.hir().local_def_id(node_id); +fn check_impl_overlap<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_id: HirId) { + let impl_def_id = tcx.hir().local_def_id_from_hir_id(hir_id); let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); let trait_def_id = trait_ref.def_id; diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs index de043277c8359..611291c2688f5 100644 --- a/src/librustdoc/passes/collect_trait_impls.rs +++ b/src/librustdoc/passes/collect_trait_impls.rs @@ -119,7 +119,7 @@ pub fn collect_trait_impls(krate: Crate, cx: &DocContext<'_>) -> Crate { // doesn't work with it anyway, so pull them from the HIR map instead for &trait_did in cx.all_traits.iter() { for &impl_node in cx.tcx.hir().trait_impls(trait_did) { - let impl_did = cx.tcx.hir().local_def_id(impl_node); + let impl_did = cx.tcx.hir().local_def_id_from_hir_id(impl_node); inline::build_impl(cx, impl_did, &mut new_items); } }