}
}
- pub fn expect_variant_data(&self, id: NodeId) -> &'hir VariantData {
+ pub fn expect_variant_data(&self, id: HirId) -> &'hir VariantData {
+ let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
+
match self.find(id) {
Some(Node::Item(i)) => {
match i.node {
}
}
- pub fn expect_variant(&self, id: NodeId) -> &'hir Variant {
+ pub fn expect_variant(&self, id: HirId) -> &'hir Variant {
+ let id = self.hir_to_node_id(id); // FIXME(@ljedrz): remove when possible
+
match self.find(id) {
Some(Node::Variant(variant)) => variant,
_ => bug!("expected variant, found {}", self.node_to_string(id)),
let def_id = field.did;
debug!("IsolatedEncoder::encode_field({:?})", def_id);
- let variant_id = tcx.hir().as_local_node_id(variant.did).unwrap();
+ let variant_id = tcx.hir().as_local_hir_id(variant.did).unwrap();
let variant_data = tcx.hir().expect_variant_data(variant_id);
Entry {
{
let tcx = self.tcx();
let lifetime_name = |def_id| {
- tcx.hir().name(tcx.hir().as_local_node_id(def_id).unwrap()).as_interned_str()
+ tcx.hir().name_by_hir_id(tcx.hir().as_local_hir_id(def_id).unwrap()).as_interned_str()
};
let r = match tcx.named_region(lifetime.hir_id) {
assert_eq!(opt_self_ty, None);
self.prohibit_generics(&path.segments);
- let node_id = tcx.hir().as_local_node_id(did).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(did).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)];
- tcx.mk_ty_param(index, 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)];
+ tcx.mk_ty_param(index, tcx.hir().name_by_hir_id(hir_id).as_interned_str())
}
Def::SelfTy(_, Some(def_id)) => {
// `Self` in impl (we know the concrete type).
in impl_m_type_params.zip(trait_m_type_params)
{
if impl_synthetic != trait_synthetic {
- let impl_node_id = tcx.hir().as_local_node_id(impl_def_id).unwrap();
- let impl_span = tcx.hir().span(impl_node_id);
+ 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 trait_span = tcx.def_span(trait_def_id);
let mut err = struct_span_err!(tcx.sess,
impl_span,
match param.kind {
GenericParamKind::Lifetime { .. } => None,
GenericParamKind::Type { .. } => {
- if param.id == impl_node_id {
+ if param.hir_id == impl_hir_id {
Some(¶m.bounds)
} else {
None
// absent. So we report an error that the Drop impl injected a
// predicate that is not present on the struct definition.
- let self_type_node_id = tcx.hir().as_local_node_id(self_type_did).unwrap();
+ let self_type_hir_id = tcx.hir().as_local_hir_id(self_type_did).unwrap();
let drop_impl_span = tcx.def_span(drop_impl_did);
// repeated `contains` calls.
if !assumptions_in_impl_context.contains(&predicate) {
- let item_span = tcx.hir().span(self_type_node_id);
+ let item_span = tcx.hir().span_by_hir_id(self_type_hir_id);
struct_span_err!(
tcx.sess,
drop_impl_span,
// Check for duplicate discriminant values
if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
let variant_did = def.variants[VariantIdx::new(i)].did;
- let variant_i_node_id = tcx.hir().as_local_node_id(variant_did).unwrap();
- let variant_i = tcx.hir().expect_variant(variant_i_node_id);
+ 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(expr.id),
- None => tcx.hir().span(variant_i_node_id)
+ Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
+ None => tcx.hir().span_by_hir_id(variant_i_hir_id)
};
let span = match v.node.disr_expr {
- Some(ref expr) => tcx.hir().span(expr.id),
+ Some(ref expr) => tcx.hir().span_by_hir_id(expr.hir_id),
None => v.span
};
struct_span_err!(tcx.sess, span, E0081,
});
for (&used, param) in types_used.iter().zip(types) {
if !used {
- let id = tcx.hir().as_local_node_id(param.def_id).unwrap();
- let span = tcx.hir().span(id);
+ let id = tcx.hir().as_local_hir_id(param.def_id).unwrap();
+ let span = tcx.hir().span_by_hir_id(id);
struct_span_err!(tcx.sess, span, E0091, "type parameter `{}` is unused", param.name)
.span_label(span, "unused type parameter")
.emit();
}
fn var_name(tcx: TyCtxt, var_hir_id: hir::HirId) -> ast::Name {
- let var_node_id = tcx.hir().hir_to_node_id(var_hir_id);
- tcx.hir().name(var_node_id)
+ tcx.hir().name_by_hir_id(var_hir_id)
}
/// not included it frequently leads to confusing errors in fn bodies. So it's better to check
/// the types first.
pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
- let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
- let item = tcx.hir().expect_item(node_id);
+ let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ let item = tcx.hir().expect_item_by_hir_id(hir_id);
- debug!("check_item_well_formed(it.id={}, it.name={})",
- item.id,
+ debug!("check_item_well_formed(it.hir_id={:?}, it.name={})",
+ item.hir_id,
tcx.item_path_str(def_id));
match item.node {
// won't be allowed unless there's an *explicit* implementation of `Send`
// for `T`
hir::ItemKind::Impl(_, polarity, defaultness, _, ref trait_ref, ref self_ty, _) => {
- let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id(item.id))
+ let is_auto = tcx.impl_trait_ref(tcx.hir().local_def_id_from_hir_id(item.hir_id))
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
if let (hir::Defaultness::Default { .. }, true) = (defaultness, is_auto) {
tcx.sess.span_err(item.span, "impls of auto traits cannot be default");
if let ty::UserType::TypeOf(_, user_substs) = c_ty.value {
if self.rustc_dump_user_substs {
// This is a unit-testing mechanism.
- let node_id = self.tcx().hir().hir_to_node_id(hir_id);
- let span = self.tcx().hir().span(node_id);
+ let span = self.tcx().hir().span_by_hir_id(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(
impl Locatable for DefIndex {
fn to_span(&self, tcx: &TyCtxt) -> Span {
- let node_id = tcx.hir().def_index_to_node_id(*self);
- tcx.hir().span(node_id)
+ let hir_id = tcx.hir().def_index_to_hir_id(*self);
+ tcx.hir().span_by_hir_id(hir_id)
}
}
impl Locatable for hir::HirId {
fn to_span(&self, tcx: &TyCtxt) -> Span {
- let node_id = tcx.hir().hir_to_node_id(*self);
- tcx.hir().span(node_id)
+ tcx.hir().span_by_hir_id(*self)
}
}
fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did: DefId) {
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
- let impl_node_id = if let Some(n) = tcx.hir().as_local_node_id(impl_did) {
+ let impl_hir_id = if let Some(n) = tcx.hir().as_local_hir_id(impl_did) {
n
} else {
debug!("visit_implementation_of_copy(): impl not in this crate");
debug!("visit_implementation_of_copy: self_type={:?} (bound)",
self_type);
- let span = tcx.hir().span(impl_node_id);
+ let span = tcx.hir().span_by_hir_id(impl_hir_id);
let param_env = tcx.param_env(impl_did);
assert!(!self_type.has_escaping_bound_vars());
match param_env.can_type_implement_copy(tcx, self_type) {
Ok(()) => {}
Err(CopyImplementationError::InfrigingFields(fields)) => {
- let item = tcx.hir().expect_item(impl_node_id);
+ let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
let span = if let ItemKind::Impl(.., Some(ref tr), _, _) = item.node {
tr.path.span
} else {
err.emit()
}
Err(CopyImplementationError::NotAnAdt) => {
- let item = tcx.hir().expect_item(impl_node_id);
+ let item = tcx.hir().expect_item_by_hir_id(impl_hir_id);
let span = if let ItemKind::Impl(.., ref ty, _) = item.node {
ty.span
} else {
}
fn trait_def<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty::TraitDef {
- let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
- let item = tcx.hir().expect_item(node_id);
+ let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ let item = tcx.hir().expect_item_by_hir_id(hir_id);
let (is_auto, unsafety) = match item.node {
hir::ItemKind::Trait(is_auto, unsafety, ..) => (is_auto == hir::IsAuto::Yes, unsafety),
) -> Option<ty::TraitRef<'tcx>> {
let icx = ItemCtxt::new(tcx, def_id);
- let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
- match tcx.hir().expect_item(node_id).node {
+ let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ match tcx.hir().expect_item_by_hir_id(hir_id).node {
hir::ItemKind::Impl(.., ref opt_trait_ref, _, _) => {
opt_trait_ref.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
}
fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> hir::ImplPolarity {
- let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
- match tcx.hir().expect_item(node_id).node {
+ let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
+ match tcx.hir().expect_item_by_hir_id(hir_id).node {
hir::ItemKind::Impl(_, polarity, ..) => polarity,
ref item => bug!("impl_polarity: {:?} not an impl", item),
}
fn variances_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_def_id: DefId)
-> Lrc<Vec<ty::Variance>> {
- let id = tcx.hir().as_local_node_id(item_def_id).expect("expected local def-id");
+ 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(id), "asked to compute variance for wrong kind of item")
+ span_bug!(tcx.hir().span_by_hir_id(id), "asked to compute variance for wrong kind of item")
};
- match tcx.hir().get(id) {
+ match tcx.hir().get_by_hir_id(id) {
Node::Item(item) => match item.node {
hir::ItemKind::Enum(..) |
hir::ItemKind::Struct(..) |