}
}
- fn is_body_owner(self, node_id: NodeId) -> bool {
+ fn is_body_owner(self, hir_id: HirId) -> bool {
match self.associated_body() {
- Some(b) => b.node_id == node_id,
+ Some(b) => b.hir_id == hir_id,
None => false,
}
}
}
pub fn body(&self, id: BodyId) -> &'hir Body {
- self.read(id.node_id);
+ self.read_by_hir_id(id.hir_id);
// N.B., intentionally bypass `self.forest.krate()` so that we
// do not trigger a read of the whole krate here
/// 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 { node_id }: BodyId) -> NodeId {
+ pub fn body_owner(&self, BodyId { hir_id }: BodyId) -> NodeId {
+ let node_id = self.hir_to_node_id(hir_id);
let parent = self.get_parent_node(node_id);
- assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(node_id)));
+ assert!(self.map[parent.as_usize()].map_or(false, |e| e.is_body_owner(hir_id)));
parent
}
}
}
+ // FIXME(@ljedrz): replace the NodeId variant
+ pub fn maybe_body_owned_by_by_hir_id(&self, id: HirId) -> Option<BodyId> {
+ let node_id = self.hir_to_node_id(id);
+ self.maybe_body_owned_by(node_id)
+ }
+
/// Given a body owner's id, returns the `BodyId` associated with it.
pub fn body_owned_by(&self, id: NodeId) -> BodyId {
self.maybe_body_owned_by(id).unwrap_or_else(|| {
}
}
+ // FIXME(@ljedrz): replace the NodeId variant
+ pub fn body_owner_kind_by_hir_id(&self, id: HirId) -> BodyOwnerKind {
+ let node_id = self.hir_to_node_id(id);
+ self.body_owner_kind(node_id)
+ }
+
pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
match self.get(id) {
Node::Item(&Item { node: ItemKind::Trait(..), .. }) => id,
self.local_def_id(self.get_module_parent_node(id))
}
+ // FIXME(@ljedrz): replace the NodeId variant
+ pub fn get_module_parent_by_hir_id(&self, id: HirId) -> DefId {
+ let node_id = self.hir_to_node_id(id);
+ self.get_module_parent(node_id)
+ }
+
/// Returns the `NodeId` of `id`'s nearest module parent, or `id` itself if no
/// module parent is in this map.
pub fn get_module_parent_node(&self, id: NodeId) -> NodeId {
/// the `local_id` part of the `HirId` changing, which is a very useful property in
/// incremental compilation where we have to persist things through changes to
/// the code base.
-#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, PartialOrd, Ord)]
pub struct HirId {
pub owner: DefIndex,
pub local_id: ItemLocalId,
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct BodyId {
- pub node_id: NodeId,
+ pub hir_id: HirId,
}
/// The body of a function, closure, or constant value. In the case of
impl Body {
pub fn id(&self) -> BodyId {
BodyId {
- node_id: self.value.id
+ hir_id: self.value.hir_id,
}
}
}
fn to_stable_hash_key(&self,
hcx: &StableHashingContext<'a>)
-> (DefPathHash, hir::ItemLocalId) {
- let hir::BodyId { node_id } = *self;
- node_id.to_stable_hash_key(hcx)
+ let hir::BodyId { hir_id } = *self;
+ hir_id.to_stable_hash_key(hcx)
}
}
};
if let Some(body_id) = body_id {
- let expr = self.tcx.hir().expect_expr(body_id.node_id);
+ let expr = self.tcx.hir().expect_expr_by_hir_id(body_id.hir_id);
local_visitor.visit_expr(expr);
}
pub use self::ValuePairs::*;
pub use crate::ty::IntVarValue;
+use crate::hir;
use crate::hir::def_id::DefId;
use crate::infer::canonical::{Canonical, CanonicalVarValues};
use crate::middle::free_region::RegionRelations;
// for each body-id in this map, which will process the
// obligations within. This is expected to be done 'late enough'
// that all type inference variables have been bound and so forth.
- pub region_obligations: RefCell<Vec<(ast::NodeId, RegionObligation<'tcx>)>>,
+ pub region_obligations: RefCell<Vec<(hir::HirId, RegionObligation<'tcx>)>>,
/// What is the innermost universe we have created? Starts out as
/// `UniverseIndex::root()` but grows from there as we enter
pub fn partially_normalize_associated_types_in<T>(
&self,
span: Span,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
) -> InferOk<'tcx, T>
pub fn instantiate_opaque_types<T: TypeFoldable<'tcx>>(
&self,
parent_def_id: DefId,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T,
) -> InferOk<'tcx, (T, OpaqueTypeMap<'tcx>)> {
struct Instantiator<'a, 'gcx: 'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
parent_def_id: DefId,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
opaque_types: OpaqueTypeMap<'tcx>,
obligations: Vec<PredicateObligation<'tcx>>,
use crate::infer::outlives::free_region_map::FreeRegionMap;
use crate::infer::{GenericKind, InferCtxt};
+use crate::hir;
use rustc_data_structures::fx::FxHashMap;
-use syntax::ast;
use syntax_pos::Span;
use crate::traits::query::outlives_bounds::{self, OutlivesBound};
use crate::ty::{self, Ty};
// results when proving outlives obligations like `T: 'x` later
// (e.g., if `T: 'x` must be proven within the body B1, then we
// know it is true if either `'a: 'x` or `'b: 'x`).
- region_bound_pairs_map: FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
+ region_bound_pairs_map: FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
// Used to compute `region_bound_pairs_map`: contains the set of
// in-scope region-bound pairs thus far.
}
/// Borrows current value of the `region_bound_pairs`.
- pub fn region_bound_pairs_map(&self) -> &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>> {
+ pub fn region_bound_pairs_map(&self) -> &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>> {
&self.region_bound_pairs_map
}
&mut self,
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
fn_sig_tys: &[Ty<'tcx>],
- body_id: ast::NodeId,
+ body_id: hir::HirId,
span: Span,
) {
debug!("add_implied_bounds()");
}
/// Save the current set of region-bound pairs under the given `body_id`.
- pub fn save_implied_bounds(&mut self, body_id: ast::NodeId) {
+ pub fn save_implied_bounds(&mut self, body_id: hir::HirId) {
let old = self.region_bound_pairs_map.insert(
body_id,
self.region_bound_pairs_accum.clone(),
use crate::infer::outlives::verify::VerifyBoundCx;
use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
use rustc_data_structures::fx::FxHashMap;
-use syntax::ast;
+use crate::hir;
use crate::traits::ObligationCause;
use crate::ty::outlives::Component;
use crate::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
/// information).
pub fn register_region_obligation(
&self,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
obligation: RegionObligation<'tcx>,
) {
debug!(
}
/// Trait queries just want to pass back type obligations "as is"
- pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
+ pub fn take_registered_region_obligations(&self) -> Vec<(hir::HirId, RegionObligation<'tcx>)> {
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
}
/// processed.
pub fn process_registered_region_obligations(
&self,
- region_bound_pairs_map: &FxHashMap<ast::NodeId, RegionBoundPairs<'tcx>>,
+ region_bound_pairs_map: &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
implicit_region_bound: Option<ty::Region<'tcx>>,
param_env: ty::ParamEnv<'tcx>,
) {
full_env,
ty,
trait_did,
- ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID),
+ ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID),
);
fulfill.select_all_or_error(&infcx).unwrap_or_else(|e| {
panic!(
user_env.caller_bounds.iter().cloned().collect();
let mut new_env = param_env.clone();
- let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
+ let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
while let Some(pred) = predicates.pop_front() {
infcx.clear_caches();
select: &mut SelectionContext<'c, 'd, 'cx>,
only_projections: bool,
) -> bool {
- let dummy_cause = ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID);
+ let dummy_cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
for (obligation, mut predicate) in nested
.map(|o| (o.clone(), o.predicate.clone()))
/// (in particular, closures can add new assumptions). See the
/// field `region_obligations` of the `FulfillmentContext` for more
/// information.
- pub body_id: ast::NodeId,
+ pub body_id: hir::HirId,
pub code: ObligationCauseCode<'tcx>
}
};
let obligation = Obligation {
param_env,
- cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
+ cause: ObligationCause::misc(span, hir::DUMMY_HIR_ID),
recursion_depth: 0,
predicate: trait_ref.to_predicate(),
};
// We can use a dummy node-id here because we won't pay any mind
// to region obligations that arise (there shouldn't really be any
// anyhow).
- let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
+ let cause = ObligationCause::misc(span, hir::DUMMY_HIR_ID);
fulfill_cx.register_bound(infcx, param_env, ty, def_id, cause);
}
pub fn misc(span: Span,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
trait_ref: O)
-> Obligation<'tcx, O> {
impl<'tcx> ObligationCause<'tcx> {
#[inline]
pub fn new(span: Span,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
code: ObligationCauseCode<'tcx>)
-> ObligationCause<'tcx> {
- ObligationCause { span: span, body_id: body_id, code: code }
+ ObligationCause { span, body_id, code }
}
- pub fn misc(span: Span, body_id: ast::NodeId) -> ObligationCause<'tcx> {
- ObligationCause { span: span, body_id: body_id, code: MiscObligation }
+ pub fn misc(span: Span, body_id: hir::HirId) -> ObligationCause<'tcx> {
+ ObligationCause { span, body_id, code: MiscObligation }
}
pub fn dummy() -> ObligationCause<'tcx> {
- ObligationCause { span: DUMMY_SP, body_id: ast::CRATE_NODE_ID, code: MiscObligation }
+ ObligationCause { span: DUMMY_SP, body_id: hir::CRATE_HIR_ID, code: MiscObligation }
}
}
use crate::infer::InferCtxt;
use crate::infer::canonical::OriginalQueryValues;
-use syntax::ast;
+use crate::hir;
use syntax::source_map::Span;
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt};
use crate::traits::query::NoSolution;
pub fn implied_outlives_bounds(
&self,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
ty: Ty<'tcx>,
span: Span,
) -> Vec<OutlivesBound<'tcx>> {
use rustc_data_structures::sync::{self, Lrc, ParallelIterator, par_iter};
use std::slice;
use std::{mem, ptr};
-use syntax::ast::{self, DUMMY_NODE_ID, Name, Ident, NodeId};
+use syntax::ast::{self, Name, Ident, NodeId};
use syntax::attr;
use syntax::ext::hygiene::Mark;
use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
pub fn find_field_index(self, ident: Ident, variant: &VariantDef) -> Option<usize> {
variant.fields.iter().position(|field| {
- self.adjust_ident(ident, variant.did, DUMMY_NODE_ID).0 == field.ident.modern()
+ self.adjust_ident(ident, variant.did, hir::DUMMY_HIR_ID).0 == field.ident.modern()
})
}
/// its supposed definition name (`def_name`). The method also needs `DefId` of the supposed
/// definition's parent/scope to perform comparison.
pub fn hygienic_eq(self, use_name: Ident, def_name: Ident, def_parent_def_id: DefId) -> bool {
- self.adjust_ident(use_name, def_parent_def_id, DUMMY_NODE_ID).0 == def_name.modern()
+ self.adjust_ident(use_name, def_parent_def_id, hir::DUMMY_HIR_ID).0 == def_name.modern()
}
- pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: NodeId) -> (Ident, DefId) {
+ pub fn adjust_ident(self, mut ident: Ident, scope: DefId, block: hir::HirId) -> (Ident, DefId) {
ident = ident.modern();
let target_expansion = match scope.krate {
LOCAL_CRATE => self.hir().definitions().expansion_that_defined(scope.index),
let scope = match ident.span.adjust(target_expansion) {
Some(actual_expansion) =>
self.hir().definitions().parent_module_of_macro_def(actual_expansion),
- None if block == DUMMY_NODE_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId
- None => self.hir().get_module_parent(block),
+ None if block == hir::DUMMY_HIR_ID => DefId::local(CRATE_DEF_INDEX), // Dummy DefId
+ None => self.hir().get_module_parent_by_hir_id(block),
};
(ident, scope)
}
if tcx.sess.opts.debugging_opts.chalk { Some(def_id) } else { None }
);
- let body_id = tcx.hir().as_local_node_id(def_id).map_or(DUMMY_NODE_ID, |id| {
- tcx.hir().maybe_body_owned_by(id).map_or(id, |body| body.node_id)
+ 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)
});
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
+use crate::hir;
use crate::hir::def_id::DefId;
use crate::infer::InferCtxt;
use crate::ty::subst::Substs;
use crate::traits;
use crate::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
use std::iter::once;
-use syntax::ast;
use syntax_pos::Span;
use crate::middle::lang_items;
/// say "$0 is WF if $0 is WF".
pub fn obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
ty: Ty<'tcx>,
span: Span)
-> Option<Vec<traits::PredicateObligation<'tcx>>>
/// if `Bar: Eq`.
pub fn trait_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
trait_ref: &ty::TraitRef<'tcx>,
span: Span)
-> Vec<traits::PredicateObligation<'tcx>>
pub fn predicate_obligations<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
predicate: &ty::Predicate<'tcx>,
span: Span)
-> Vec<traits::PredicateObligation<'tcx>>
struct WfPredicates<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
span: Span,
out: Vec<traits::PredicateObligation<'tcx>>,
}
match tcx.hir().get(closure_id) {
Node::Expr(expr) => match expr.node {
hir::ExprKind::Closure(.., body_id, _, _) => {
- body_id.node_id
+ tcx.hir().hir_to_node_id(body_id.hir_id)
}
_ => {
bug!("encountered non-closure id: {}", closure_id)
}
let def_id = src.def_id();
- let id = tcx.hir().as_local_node_id(def_id).unwrap();
+ 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(id) {
+ let mode = match tcx.hir().body_owner_kind_by_hir_id(id) {
hir::BodyOwnerKind::Closure => Mode::Fn,
hir::BodyOwnerKind::Fn => {
if tcx.is_const_fn(def_id) {
let node_id = tcx.hir().as_local_node_id(def_id)
.expect("rvalue_promotable_map invoked with non-local def-id");
let body_id = tcx.hir().body_owned_by(node_id);
- let body_hir_id = tcx.hir().node_to_hir_id(body_id.node_id);
- tcx.rvalue_promotable_map(def_id).contains(&body_hir_id.local_id)
+ tcx.rvalue_promotable_map(def_id).contains(&body_id.hir_id.local_id)
}
fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def: &'tcx ty::AdtDef, // definition of the struct or enum
field: &'tcx ty::FieldDef) { // definition of the field
let ident = Ident::new(keywords::Invalid.name(), use_ctxt);
- let def_id = self.tcx.adjust_ident(ident, def.did, self.current_item).1;
+ let current_hir = self.tcx.hir().node_to_hir_id(self.current_item);
+ let def_id = self.tcx.adjust_ident(ident, def.did, current_hir).1;
if !def.is_enum() && !field.vis.is_accessible_from(def_id, self.tcx) {
struct_span_err!(self.tcx.sess, span, E0451, "field `{}` of {} `{}` is private",
field.ident, def.variant_descr(), self.tcx.item_path_str(def.did))
//! Provider for the `implied_outlives_bounds` query.
//! Do not call this query directory. See [`rustc::traits::query::implied_outlives_bounds`].
+use rustc::hir;
use rustc::infer::InferCtxt;
use rustc::infer::canonical::{self, Canonical};
use rustc::traits::{TraitEngine, TraitEngineExt};
use rustc::ty::query::Providers;
use rustc::ty::wf;
use smallvec::{SmallVec, smallvec};
-use syntax::ast::DUMMY_NODE_ID;
use syntax::source_map::DUMMY_SP;
use rustc::traits::FulfillmentContext;
// unresolved inference variables here anyway, but there might be
// during typeck under some circumstances.)
let obligations =
- wf::obligations(infcx, param_env, DUMMY_NODE_ID, ty, DUMMY_SP).unwrap_or(vec![]);
+ wf::obligations(infcx, param_env, hir::DUMMY_HIR_ID, ty, DUMMY_SP).unwrap_or(vec![]);
// N.B., all of these predicates *ought* to be easily proven
// true. In fact, their correctness is (mostly) implied by
+use rustc::hir;
use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::traits::query::{normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution};
use rustc::traits::{self, ObligationCause, SelectionContext, TraitEngineExt};
use rustc::ty::{ParamEnvAnd, TyCtxt};
use rustc_data_structures::sync::Lrc;
use std::sync::atomic::Ordering;
-use syntax::ast::DUMMY_NODE_ID;
use syntax_pos::DUMMY_SP;
crate fn provide(p: &mut Providers<'_>) {
value: goal,
}| {
let selcx = &mut SelectionContext::new(infcx);
- let cause = ObligationCause::misc(DUMMY_SP, DUMMY_NODE_ID);
+ let cause = ObligationCause::misc(DUMMY_SP, hir::DUMMY_HIR_ID);
let mut obligations = vec![];
let answer = traits::normalize_projection_type(
selcx,
use rustc::infer::at::ToTrace;
use rustc::infer::canonical::{Canonical, QueryResponse};
use rustc::infer::InferCtxt;
+use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::traits::query::type_op::ascribe_user_type::AscribeUserType;
use rustc::traits::query::type_op::eq::Eq;
};
use rustc_data_structures::sync::Lrc;
use std::fmt;
-use syntax::ast;
use syntax_pos::DUMMY_SP;
crate fn provide(p: &mut Providers<'_>) {
self.infcx
.partially_normalize_associated_types_in(
DUMMY_SP,
- ast::CRATE_NODE_ID,
+ hir::CRATE_HIR_ID,
self.param_env,
&value,
)
binding.item_name, binding.span)
}?;
+ let hir_ref_id = self.tcx().hir().node_to_hir_id(ref_id);
let (assoc_ident, def_scope) =
- tcx.adjust_ident(binding.item_name, candidate.def_id(), ref_id);
+ tcx.adjust_ident(binding.item_name, candidate.def_id(), hir_ref_id);
let assoc_ty = tcx.associated_items(candidate.def_id()).find(|i| {
i.kind == ty::AssociatedKind::Type && i.ident.modern() == assoc_ident
}).expect("missing associated type");
};
let trait_did = bound.def_id();
- let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_ident, trait_did, ref_id);
+ let hir_ref_id = self.tcx().hir().node_to_hir_id(ref_id);
+ let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_ident, trait_did, hir_ref_id);
let item = tcx.associated_items(trait_did).find(|i| {
Namespace::from(i.kind) == Namespace::Type &&
i.ident.modern() == assoc_ident
use super::{FnCtxt, PlaceOp, Needs};
use super::method::MethodCallee;
+use rustc::hir;
use rustc::infer::{InferCtxt, InferOk};
use rustc::session::DiagnosticMessageId;
use rustc::traits::{self, TraitEngine};
use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref};
use syntax_pos::Span;
-use syntax::ast::{self, Ident};
+use syntax::ast::Ident;
use std::iter;
pub struct Autoderef<'a, 'gcx: 'tcx, 'tcx: 'a> {
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
steps: Vec<(Ty<'tcx>, AutoderefKind)>,
cur_ty: Ty<'tcx>,
impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
span: Span,
base_ty: Ty<'tcx>)
-> Autoderef<'a, 'gcx, 'tcx>
.liberate_late_bound_regions(expr_def_id, &bound_sig);
let liberated_sig = self.inh.normalize_associated_types_in(
body.value.span,
- body.value.id,
+ body.value.hir_id,
self.param_env,
&liberated_sig,
);
// `ObligationCause` (and the `FnCtxt`). This is what
// `regionck_item` expects.
let impl_m_node_id = tcx.hir().as_local_node_id(impl_m.def_id).unwrap();
+ let impl_m_hir_id = tcx.hir().node_to_hir_id(impl_m_node_id);
let cause = ObligationCause {
span: impl_m_span,
- body_id: impl_m_node_id,
+ body_id: impl_m_hir_id,
code: ObligationCauseCode::CompareImplMethodObligation {
item_name: impl_m.ident.name,
impl_item_def_id: impl_m.def_id,
// Construct trait parameter environment and then shift it into the placeholder viewpoint.
// The key step here is to update the caller_bounds's predicates to be
// the new hybrid bounds we computed.
- let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_node_id);
+ let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_hir_id);
let param_env = ty::ParamEnv::new(
tcx.intern_predicates(&hybrid_preds.predicates),
Reveal::UserFacing,
);
let impl_sig =
inh.normalize_associated_types_in(impl_m_span,
- impl_m_node_id,
+ impl_m_hir_id,
param_env,
&impl_sig);
let impl_fty = tcx.mk_fn_ptr(ty::Binder::bind(impl_sig));
trait_sig.subst(tcx, trait_to_skol_substs);
let trait_sig =
inh.normalize_associated_types_in(impl_m_span,
- impl_m_node_id,
+ impl_m_hir_id,
param_env,
&trait_sig);
let trait_fty = tcx.mk_fn_ptr(ty::Binder::bind(trait_sig));
// Finally, resolve all regions. This catches wily misuses of
// lifetime parameters.
- let fcx = FnCtxt::new(&inh, param_env, impl_m_node_id);
- fcx.regionck_item(impl_m_node_id, impl_m_span, &[]);
+ let fcx = FnCtxt::new(&inh, param_env, impl_m_hir_id);
+ fcx.regionck_item(impl_m_hir_id, impl_m_span, &[]);
Ok(())
})
// Create a parameter environment that represents the implementation's
// method.
let impl_c_node_id = tcx.hir().as_local_node_id(impl_c.def_id).unwrap();
+ let impl_c_hir_id = tcx.hir().node_to_hir_id(impl_c_node_id);
// Compute placeholder form of impl and trait const tys.
let impl_ty = tcx.type_of(impl_c.def_id);
let trait_ty = tcx.type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs);
- let mut cause = ObligationCause::misc(impl_c_span, impl_c_node_id);
+ let mut cause = ObligationCause::misc(impl_c_span, impl_c_hir_id);
// There is no "body" here, so just pass dummy id.
let impl_ty = inh.normalize_associated_types_in(impl_c_span,
- impl_c_node_id,
+ impl_c_hir_id,
param_env,
&impl_ty);
debug!("compare_const_impl: impl_ty={:?}", impl_ty);
let trait_ty = inh.normalize_associated_types_in(impl_c_span,
- impl_c_node_id,
+ impl_c_hir_id,
param_env,
&trait_ty);
return;
}
- let fcx = FnCtxt::new(&inh, param_env, impl_c_node_id);
- fcx.regionck_item(impl_c_node_id, impl_c_span, &[]);
+ let fcx = FnCtxt::new(&inh, param_env, impl_c_hir_id);
+ fcx.regionck_item(impl_c_hir_id, impl_c_span, &[]);
});
}
use crate::check::regionck::RegionCtxt;
+use crate::hir;
use crate::hir::def_id::DefId;
use rustc::infer::outlives::env::OutlivesEnvironment;
use rustc::infer::{self, InferOk, SuppressRegionErrors};
use rustc::ty::{self, Ty, TyCtxt};
use crate::util::common::ErrorReported;
-use syntax::ast;
use syntax_pos::Span;
/// This function confirms that the `Drop` implementation identified by
drop_impl_ty: Ty<'tcx>,
self_type_did: DefId,
) -> Result<(), ErrorReported> {
- let drop_impl_node_id = tcx.hir().as_local_node_id(drop_impl_did).unwrap();
+ let drop_impl_hir_id = tcx.hir().as_local_hir_id(drop_impl_did).unwrap();
// check that the impl type can be made to match the trait type.
let fresh_impl_substs = infcx.fresh_substs_for_item(drop_impl_span, drop_impl_did);
let fresh_impl_self_ty = drop_impl_ty.subst(tcx, fresh_impl_substs);
- let cause = &ObligationCause::misc(drop_impl_span, drop_impl_node_id);
+ let cause = &ObligationCause::misc(drop_impl_span, drop_impl_hir_id);
match infcx
.at(cause, impl_param_env)
.eq(named_type, fresh_impl_self_ty)
rcx: &mut RegionCtxt<'a, 'gcx, 'tcx>,
ty: Ty<'tcx>,
span: Span,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
scope: region::Scope,
) -> Result<(), ErrorReported> {
debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}",
safety,
abi
)));
- let cause = ObligationCause::new(it.span, it.id, ObligationCauseCode::IntrinsicType);
+ let cause = ObligationCause::new(it.span, it.hir_id, ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(def_id)), fty);
}
tcx.infer_ctxt().enter_with_canonical(DUMMY_SP, &goal, |ref infcx, goal, inference_vars| {
let ParamEnvAnd { param_env, value: self_ty } = goal;
- let mut autoderef = Autoderef::new(infcx, param_env, ast::DUMMY_NODE_ID, DUMMY_SP, self_ty)
+ let mut autoderef = Autoderef::new(infcx, param_env, hir::DUMMY_HIR_ID, DUMMY_SP, self_ty)
.include_raw_pointers()
.silence_errors();
let mut reached_raw_pointer = false;
stable_pick: &Pick,
unstable_candidates: &[(&Candidate<'tcx>, Symbol)],
) {
- let mut diag = self.tcx.struct_span_lint_node(
+ let mut diag = self.tcx.struct_span_lint_hir(
lint::builtin::UNSTABLE_NAME_COLLISIONS,
self.fcx.body_id,
self.span,
};
let field_ty = field.ty(tcx, substs);
- let scope = self.tcx.hir().get_module_parent(self.body_id);
+ let scope = self.tcx.hir().get_module_parent_by_hir_id(
+ self.body_id);
if field.vis.is_accessible_from(scope, self.tcx) {
if self.is_fn_ty(&field_ty, span) {
err.help(&format!("use `({0}.{1})(...)` if you \
err: &mut DiagnosticBuilder,
mut msg: String,
candidates: Vec<DefId>) {
- let module_did = self.tcx.hir().get_module_parent(self.body_id);
+ let module_did = self.tcx.hir().get_module_parent_by_hir_id(self.body_id);
let module_id = self.tcx.hir().as_local_node_id(module_did).unwrap();
let krate = self.tcx.hir().krate();
let (span, found_use) = UsePlacementFinder::check(self.tcx, krate, module_id);
}
pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
- body_id: ast::NodeId,
+ body_id: hir::HirId,
/// The parameter environment used for proving trait obligations
/// in this function. This can change when we descend into
fn normalize_associated_types_in<T>(&self,
span: Span,
- body_id: ast::NodeId,
+ body_id: hir::HirId,
param_env: ty::ParamEnv<'tcx>,
value: &T) -> T
where T : TypeFoldable<'tcx>
tcx.liberate_late_bound_regions(def_id, &fn_sig);
let fn_sig =
inh.normalize_associated_types_in(body.value.span,
- body_id.node_id,
+ body_id.hir_id,
param_env,
&fn_sig);
let fcx = check_fn(&inh, param_env, fn_sig, decl, id, body, None).0;
fcx
} else {
- let fcx = FnCtxt::new(&inh, param_env, body.value.id);
+ let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
let expected_type = tcx.type_of(def_id);
let expected_type = fcx.normalize_associated_types_in(body.value.span, &expected_type);
fcx.require_type_is_sized(expected_type, body.value.span, traits::ConstSized);
// Create the function context. This is either derived from scratch or,
// in the case of closures, based on the outer context.
- let mut fcx = FnCtxt::new(inherited, param_env, body.value.id);
+ let mut fcx = FnCtxt::new(inherited, param_env, body.value.hir_id);
*fcx.ps.borrow_mut() = UnsafetyState::function(fn_sig.unsafety, fn_id);
let declared_ret_ty = fn_sig.output();
let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]);
let trait_ref = ty::TraitRef::new(term_id, substs);
let return_ty_span = decl.output.span();
+ let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id);
let cause = traits::ObligationCause::new(
- return_ty_span, fn_id, ObligationCauseCode::MainFunctionType);
+ return_ty_span, fn_hir_id, ObligationCauseCode::MainFunctionType);
inherited.register_predicate(
traits::Obligation::new(
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pub fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
- body_id: ast::NodeId)
+ body_id: hir::HirId)
-> FnCtxt<'a, 'gcx, 'tcx> {
FnCtxt {
body_id,
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pub fn regionck_expr(&self, body: &'gcx hir::Body) {
let subject = self.tcx.hir().body_owner_def_id(body.id());
- let id = body.value.id;
+ let id = body.value.hir_id;
let mut rcx = RegionCtxt::new(
self,
RepeatingScope(id),
/// Region checking during the WF phase for items. `wf_tys` are the
/// types from which we should derive implied bounds, if any.
- pub fn regionck_item(&self, item_id: ast::NodeId, span: Span, wf_tys: &[Ty<'tcx>]) {
+ pub fn regionck_item(&self, item_id: hir::HirId, span: Span, wf_tys: &[Ty<'tcx>]) {
debug!("regionck_item(item.id={:?}, wf_tys={:?})", item_id, wf_tys);
- let subject = self.tcx.hir().local_def_id(item_id);
+ let subject = self.tcx.hir().local_def_id_from_hir_id(item_id);
let mut rcx = RegionCtxt::new(
self,
RepeatingScope(item_id),
pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) {
debug!("regionck_fn(id={})", fn_id);
let subject = self.tcx.hir().body_owner_def_id(body.id());
- let node_id = body.value.id;
+ let hir_id = body.value.hir_id;
let mut rcx = RegionCtxt::new(
self,
- RepeatingScope(node_id),
- node_id,
+ RepeatingScope(hir_id),
+ hir_id,
Subject(subject),
self.param_env,
);
if self.err_count_since_creation() == 0 {
+ let fn_hir_id = self.tcx.hir().node_to_hir_id(fn_id);
// regionck assumes typeck succeeded
- rcx.visit_fn_body(fn_id, body, self.tcx.hir().span(fn_id));
+ rcx.visit_fn_body(fn_hir_id, body, self.tcx.hir().span_by_hir_id(fn_hir_id));
}
rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx));
outlives_environment: OutlivesEnvironment<'tcx>,
// id of innermost fn body id
- body_id: ast::NodeId,
+ body_id: hir::HirId,
// call_site scope of innermost fn
call_site_scope: Option<region::Scope>,
// id of innermost fn or loop
- repeating_scope: ast::NodeId,
+ repeating_scope: hir::HirId,
// id of AST node being analyzed (the subject of the analysis).
subject_def_id: DefId,
}
}
-pub struct RepeatingScope(ast::NodeId);
+pub struct RepeatingScope(hir::HirId);
pub struct Subject(DefId);
impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
pub fn new(
fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
RepeatingScope(initial_repeating_scope): RepeatingScope,
- initial_body_id: ast::NodeId,
+ initial_body_id: hir::HirId,
Subject(subject): Subject,
param_env: ty::ParamEnv<'tcx>,
) -> RegionCtxt<'a, 'gcx, 'tcx> {
}
}
- fn set_repeating_scope(&mut self, scope: ast::NodeId) -> ast::NodeId {
+ fn set_repeating_scope(&mut self, scope: hir::HirId) -> hir::HirId {
mem::replace(&mut self.repeating_scope, scope)
}
/// `intravisit::Visitor` impl below.)
fn visit_fn_body(
&mut self,
- id: ast::NodeId, // the id of the fn itself
+ id: hir::HirId, // the id of the fn itself
body: &'gcx hir::Body,
span: Span,
) {
// When we enter a function, we can derive
- debug!("visit_fn_body(id={})", id);
+ debug!("visit_fn_body(id={:?})", id);
let body_id = body.id();
- self.body_id = body_id.node_id;
+ self.body_id = body_id.hir_id;
let call_site = region::Scope {
id: body.value.hir_id.local_id,
self.call_site_scope = Some(call_site);
let fn_sig = {
- let fn_hir_id = self.tcx.hir().node_to_hir_id(id);
- match self.tables.borrow().liberated_fn_sigs().get(fn_hir_id) {
+ match self.tables.borrow().liberated_fn_sigs().get(id) {
Some(f) => f.clone(),
None => {
- bug!("No fn-sig entry for id={}", id);
+ bug!("No fn-sig entry for id={:?}", id);
}
}
};
self.outlives_environment.add_implied_bounds(
self.fcx,
&fn_sig_tys[..],
- body_id.node_id,
+ body_id.hir_id,
span,
);
self.outlives_environment
- .save_implied_bounds(body_id.node_id);
+ .save_implied_bounds(body_id.hir_id);
self.link_fn_args(
region::Scope {
id: body.value.hir_id.local_id,
&body.arguments,
);
self.visit_body(body);
- self.visit_region_obligations(body_id.node_id);
+ self.visit_region_obligations(body_id.hir_id);
let call_site_scope = self.call_site_scope.unwrap();
debug!(
);
let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope));
- let body_hir_id = self.tcx.hir().node_to_hir_id(body_id.node_id);
- self.type_of_node_must_outlive(infer::CallReturn(span), body_hir_id, call_site_region);
+ self.type_of_node_must_outlive(infer::CallReturn(span), body_id.hir_id, call_site_region);
self.constrain_opaque_types(
&self.fcx.opaque_types.borrow(),
);
}
- fn visit_region_obligations(&mut self, node_id: ast::NodeId) {
- debug!("visit_region_obligations: node_id={}", node_id);
+ fn visit_region_obligations(&mut self, hir_id: hir::HirId) {
+ debug!("visit_region_obligations: hir_id={:?}", hir_id);
// region checking can introduce new pending obligations
// which, when processed, might generate new region
let env_snapshot = self.outlives_environment.push_snapshot_pre_closure();
let body = self.tcx.hir().body(body_id);
- self.visit_fn_body(id, body, span);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
+ self.visit_fn_body(hir_id, body, span);
// Restore state from previous function.
self.outlives_environment
fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
debug!(
- "regionck::visit_expr(e={:?}, repeating_scope={})",
+ "regionck::visit_expr(e={:?}, repeating_scope={:?})",
expr, self.repeating_scope
);
}
debug!(
- "regionck::visit_expr(e={:?}, repeating_scope={}) - visiting subexprs",
+ "regionck::visit_expr(e={:?}, repeating_scope={:?}) - visiting subexprs",
expr, self.repeating_scope
);
match expr.node {
}
hir::ExprKind::Loop(ref body, _, _) => {
- let repeating_scope = self.set_repeating_scope(body.id);
+ let repeating_scope = self.set_repeating_scope(body.hir_id);
intravisit::walk_expr(self, expr);
self.set_repeating_scope(repeating_scope);
}
hir::ExprKind::While(ref cond, ref body, _) => {
- let repeating_scope = self.set_repeating_scope(cond.id);
+ let repeating_scope = self.set_repeating_scope(cond.hir_id);
self.visit_expr(&cond);
- self.set_repeating_scope(body.id);
+ self.set_repeating_scope(body.hir_id);
self.visit_block(&body);
self.set_repeating_scope(repeating_scope);
}
fn check_expr_fn_block(&mut self, expr: &'gcx hir::Expr, body_id: hir::BodyId) {
- let repeating_scope = self.set_repeating_scope(body_id.node_id);
+ let repeating_scope = self.set_repeating_scope(body_id.hir_id);
intravisit::walk_expr(self, expr);
self.set_repeating_scope(repeating_scope);
}
/// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(FnCtxt<'b, 'gcx, 'tcx>)`.
struct CheckWfFcxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
inherited: super::InheritedBuilder<'a, 'gcx, 'tcx>,
- id: ast::NodeId,
+ id: hir::HirId,
span: Span,
param_env: ty::ParamEnv<'tcx>,
}
fn for_id<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: ast::NodeId, span: Span)
-> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
let def_id = tcx.hir().local_def_id(id);
+ let hir_id = tcx.hir().node_to_hir_id(id);
CheckWfFcxBuilder {
inherited: Inherited::build(tcx, def_id),
- id,
+ id: hir_id,
span,
param_env: tcx.param_env(def_id),
}
fn check_false_global_bounds<'a, 'gcx, 'tcx>(
fcx: &FnCtxt<'a, 'gcx, 'tcx>,
span: Span,
- id: ast::NodeId)
+ id: hir::HirId)
{
use rustc::ty::TypeFoldable;
let empty_env = ty::ParamEnv::empty();
- let def_id = fcx.tcx.hir().local_def_id(id);
+ let def_id = fcx.tcx.hir().local_def_id_from_hir_id(id);
let predicates = fcx.tcx.predicates_of(def_id).predicates
.iter()
.map(|(p, _)| *p)
body: &'gcx hir::Body,
rustc_dump_user_substs: bool,
) -> WritebackCx<'cx, 'gcx, 'tcx> {
- let owner = fcx.tcx.hir().definitions().node_to_hir_id(body.id().node_id);
+ let owner = body.id().hir_id;
WritebackCx {
fcx,
if impl_did.is_local() {
let dispatch_from_dyn_trait = tcx.lang_items().dispatch_from_dyn_trait().unwrap();
- let impl_node_id = tcx.hir().as_local_node_id(impl_did).unwrap();
- let span = tcx.hir().span(impl_node_id);
+ 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 source = tcx.type_of(impl_did);
assert!(!source.has_escaping_bound_vars());
};
tcx.infer_ctxt().enter(|infcx| {
- let cause = ObligationCause::misc(span, impl_node_id);
+ let cause = ObligationCause::misc(span, impl_hir_id);
use ty::TyKind::*;
match (&source.sty, &target.sty) {
});
// this provider should only get invoked for local def-ids
- let impl_node_id = gcx.hir().as_local_node_id(impl_did).unwrap_or_else(|| {
+ let impl_hir_id = gcx.hir().as_local_hir_id(impl_did).unwrap_or_else(|| {
bug!("coerce_unsized_info: invoked for non-local def-id {:?}", impl_did)
});
source,
target);
- let span = gcx.hir().span(impl_node_id);
+ let span = gcx.hir().span_by_hir_id(impl_hir_id);
let param_env = gcx.param_env(impl_did);
assert!(!source.has_escaping_bound_vars());
target);
gcx.infer_ctxt().enter(|infcx| {
- let cause = ObligationCause::misc(span, impl_node_id);
+ let cause = ObligationCause::misc(span, impl_hir_id);
let check_mutbl = |mt_a: ty::TypeAndMut<'gcx>,
mt_b: ty::TypeAndMut<'gcx>,
mk_ptr: &dyn Fn(Ty<'gcx>) -> Ty<'gcx>| {
being coerced, none found");
return err_info;
} else if diff_fields.len() > 1 {
- let item = gcx.hir().expect_item(impl_node_id);
+ let item = gcx.hir().expect_item_by_hir_id(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref t), _, _) = item.node {
t.path.span
} else {
- gcx.hir().span(impl_node_id)
+ gcx.hir().span_by_hir_id(impl_hir_id)
};
let mut err = struct_span_err!(gcx.sess,
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
// Register an obligation for `A: Trait<B>`.
- let cause = traits::ObligationCause::misc(span, impl_node_id);
+ let cause = traits::ObligationCause::misc(span, impl_hir_id);
let predicate = gcx.predicate_for_trait_def(param_env,
cause,
trait_def_id,
}
fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, main_def_id: DefId) {
- let main_id = tcx.hir().as_local_node_id(main_def_id).unwrap();
+ let main_id = tcx.hir().as_local_hir_id(main_def_id).unwrap();
let main_span = tcx.def_span(main_def_id);
let main_t = tcx.type_of(main_def_id);
match main_t.sty {
ty::FnDef(..) => {
- if let Some(Node::Item(it)) = tcx.hir().find(main_id) {
+ if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(main_id) {
if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
let mut error = false;
if !generics.params.is_empty() {
}
fn check_start_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, start_def_id: DefId) {
- let start_id = tcx.hir().as_local_node_id(start_def_id).unwrap();
+ let start_id = tcx.hir().as_local_hir_id(start_def_id).unwrap();
let start_span = tcx.def_span(start_def_id);
let start_t = tcx.type_of(start_def_id);
match start_t.sty {
ty::FnDef(..) => {
- if let Some(Node::Item(it)) = tcx.hir().find(start_id) {
+ if let Some(Node::Item(it)) = tcx.hir().find_by_hir_id(start_id) {
if let hir::ItemKind::Fn(.., ref generics, _) = it.node {
let mut error = false;
if !generics.params.is_empty() {
}
fn print_const_expr(cx: &DocContext, body: hir::BodyId) -> String {
- cx.tcx.hir().node_to_pretty_string(body.node_id)
+ cx.tcx.hir().hir_to_pretty_string(body.hir_id)
}
/// Given a type Path, resolve it to a Type using the TyCtxt