1
Fork 0

Only store a LocalDefId in hir::ForeignItem.

This commit is contained in:
Camille GILLOT 2021-02-01 00:33:38 +01:00
parent 786a80e9ea
commit 996dc8d5c5
32 changed files with 133 additions and 110 deletions

View file

@ -776,7 +776,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
}
} else {
for item in items {
let def_id = tcx.hir().local_def_id(item.id.hir_id);
let def_id = item.id.def_id;
let generics = tcx.generics_of(def_id);
let own_counts = generics.own_counts();
if generics.params.len() - own_counts.lifetimes != 0 {

View file

@ -9,7 +9,6 @@ use crate::require_same_types;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, TyCtxt};
@ -21,7 +20,6 @@ use std::iter;
fn equate_intrinsic_type<'tcx>(
tcx: TyCtxt<'tcx>,
it: &hir::ForeignItem<'_>,
def_id: DefId,
n_tps: usize,
sig: ty::PolyFnSig<'tcx>,
) {
@ -35,7 +33,7 @@ fn equate_intrinsic_type<'tcx>(
}
}
let i_n_tps = tcx.generics_of(def_id).own_counts().types;
let i_n_tps = tcx.generics_of(it.def_id).own_counts().types;
if i_n_tps != n_tps {
let span = match it.kind {
hir::ForeignItemKind::Fn(_, _, ref generics) => generics.span,
@ -51,8 +49,8 @@ fn equate_intrinsic_type<'tcx>(
}
let fty = tcx.mk_fn_ptr(sig);
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);
let cause = ObligationCause::new(it.span, it.hir_id(), ObligationCauseCode::IntrinsicType);
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.def_id)), fty);
}
/// Returns `true` if the given intrinsic is unsafe to call or not.
@ -100,8 +98,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
/// and in `library/core/src/intrinsics.rs`.
pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
let param = |n| tcx.mk_ty_param(n, Symbol::intern(&format!("P{}", n)));
let def_id = tcx.hir().local_def_id(it.hir_id).to_def_id();
let intrinsic_name = tcx.item_name(def_id);
let intrinsic_name = tcx.item_name(it.def_id.to_def_id());
let name_str = intrinsic_name.as_str();
let mk_va_list_ty = |mutbl| {
@ -370,7 +367,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
};
let sig = tcx.mk_fn_sig(inputs.into_iter(), output, false, unsafety, Abi::RustIntrinsic);
let sig = ty::Binder::bind(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig)
equate_intrinsic_type(tcx, it, n_tps, sig)
}
/// Type-check `extern "platform-intrinsic" { ... }` functions.
@ -380,7 +377,6 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
tcx.mk_ty_param(n, name)
};
let def_id = tcx.hir().local_def_id(it.hir_id).to_def_id();
let name = it.ident.name;
let (n_tps, inputs, output) = match name {
@ -464,5 +460,5 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
Abi::PlatformIntrinsic,
);
let sig = ty::Binder::dummy(sig);
equate_intrinsic_type(tcx, it, def_id, n_tps, sig)
equate_intrinsic_type(tcx, it, n_tps, sig)
}

View file

@ -154,10 +154,10 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
let it = tcx.hir().foreign_item(it.id);
match it.kind {
hir::ForeignItemKind::Fn(ref decl, ..) => {
check_item_fn(tcx, it.hir_id, it.ident, it.span, decl)
check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl)
}
hir::ForeignItemKind::Static(ref ty, ..) => {
check_item_type(tcx, it.hir_id, ty.span, true)
check_item_type(tcx, it.hir_id(), ty.span, true)
}
hir::ForeignItemKind::Type => (),
}

View file

@ -728,12 +728,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
hir::ItemKind::ForeignMod { items, .. } => {
for item in items {
let item = tcx.hir().foreign_item(item.id);
let def_id = tcx.hir().local_def_id(item.hir_id);
tcx.ensure().generics_of(def_id);
tcx.ensure().type_of(def_id);
tcx.ensure().predicates_of(def_id);
tcx.ensure().generics_of(item.def_id);
tcx.ensure().type_of(item.def_id);
tcx.ensure().predicates_of(item.def_id);
if let hir::ForeignItemKind::Fn(..) = item.kind {
tcx.ensure().fn_sig(def_id);
tcx.ensure().fn_sig(item.def_id);
}
}
}

View file

@ -110,7 +110,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
self.visit_node_helper(foreign_item.hir_id);
self.visit_node_helper(foreign_item.hir_id());
}
}
}

View file

@ -171,7 +171,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem<'_>) {
if let hir::ForeignItemKind::Fn(..) = foreign_item.kind {
self.add_inferreds_for_item(foreign_item.hir_id);
self.add_inferreds_for_item(foreign_item.hir_id());
}
}
}