Auto merge of #58153 - ljedrz:HirIdify_typeck, r=Zoxc
Partially Hiridify typeck Another step towards https://github.com/rust-lang/rust/pull/57578.
This commit is contained in:
commit
576df31bed
12 changed files with 49 additions and 47 deletions
|
|
@ -934,7 +934,9 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
|
@ -949,7 +951,9 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
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)),
|
||||
|
|
|
|||
|
|
@ -674,7 +674,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
{
|
||||
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) {
|
||||
|
|
@ -1682,12 +1682,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
|
|||
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).
|
||||
|
|
|
|||
|
|
@ -736,8 +736,8 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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,
|
||||
|
|
@ -840,7 +840,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
|
|||
// 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);
|
||||
|
||||
|
|
@ -216,7 +216,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>(
|
|||
// 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,
|
||||
|
|
|
|||
|
|
@ -1883,14 +1883,14 @@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
// 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,
|
||||
|
|
@ -5703,8 +5703,8 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
});
|
||||
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();
|
||||
|
|
|
|||
|
|
@ -650,6 +650,5 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ impl<'a, 'gcx, 'tcx> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
|
|||
/// 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 {
|
||||
|
|
@ -88,7 +88,7 @@ pub fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: Def
|
|||
// 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");
|
||||
|
|
|
|||
|
|
@ -407,8 +407,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
|
|||
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(
|
||||
|
|
@ -739,15 +738,14 @@ impl Locatable for ast::NodeId {
|
|||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
|
|||
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");
|
||||
|
|
@ -87,7 +87,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
|
|||
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());
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
|
|||
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 {
|
||||
|
|
@ -114,7 +114,7 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
|
|||
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 {
|
||||
|
|
|
|||
|
|
@ -737,8 +737,8 @@ fn super_predicates_of<'a, 'tcx>(
|
|||
}
|
||||
|
||||
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),
|
||||
|
|
@ -1509,8 +1509,8 @@ fn impl_trait_ref<'a, 'tcx>(
|
|||
) -> 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);
|
||||
|
|
@ -1522,8 +1522,8 @@ fn impl_trait_ref<'a, 'tcx>(
|
|||
}
|
||||
|
||||
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),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,12 @@ fn crate_variances<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum)
|
|||
|
||||
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(..) |
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue