Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef. As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`. This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
This commit is contained in:
commit
8fe989dd76
117 changed files with 1127 additions and 1191 deletions
|
@ -2210,8 +2210,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
self.res_to_ty(opt_self_ty, path, false)
|
||||
}
|
||||
hir::TyKind::OpaqueDef(item_id, ref lifetimes) => {
|
||||
let opaque_ty = tcx.hir().expect_item(item_id.id);
|
||||
let def_id = tcx.hir().local_def_id(item_id.id).to_def_id();
|
||||
let opaque_ty = tcx.hir().item(item_id);
|
||||
let def_id = item_id.def_id.to_def_id();
|
||||
|
||||
match opaque_ty.kind {
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn, .. }) => {
|
||||
|
|
|
@ -373,8 +373,7 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||
(fcx, gen_ty)
|
||||
}
|
||||
|
||||
pub(super) fn check_struct(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
|
||||
let def_id = tcx.hir().local_def_id(id);
|
||||
fn check_struct(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
|
||||
let def = tcx.adt_def(def_id);
|
||||
def.destructor(tcx); // force the destructor to be evaluated
|
||||
check_representable(tcx, span, def_id);
|
||||
|
@ -387,8 +386,7 @@ pub(super) fn check_struct(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
|
|||
check_packed(tcx, span, def);
|
||||
}
|
||||
|
||||
fn check_union(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) {
|
||||
let def_id = tcx.hir().local_def_id(id);
|
||||
fn check_union(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) {
|
||||
let def = tcx.adt_def(def_id);
|
||||
def.destructor(tcx); // force the destructor to be evaluated
|
||||
check_representable(tcx, span, def_id);
|
||||
|
@ -683,34 +681,32 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||
|
||||
pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
||||
debug!(
|
||||
"check_item_type(it.hir_id={}, it.name={})",
|
||||
it.hir_id,
|
||||
tcx.def_path_str(tcx.hir().local_def_id(it.hir_id).to_def_id())
|
||||
"check_item_type(it.def_id={:?}, it.name={})",
|
||||
it.def_id,
|
||||
tcx.def_path_str(it.def_id.to_def_id())
|
||||
);
|
||||
let _indenter = indenter();
|
||||
match it.kind {
|
||||
// Consts can play a role in type-checking, so they are included here.
|
||||
hir::ItemKind::Static(..) => {
|
||||
let def_id = tcx.hir().local_def_id(it.hir_id);
|
||||
tcx.ensure().typeck(def_id);
|
||||
maybe_check_static_with_link_section(tcx, def_id, it.span);
|
||||
check_static_inhabited(tcx, def_id, it.span);
|
||||
tcx.ensure().typeck(it.def_id);
|
||||
maybe_check_static_with_link_section(tcx, it.def_id, it.span);
|
||||
check_static_inhabited(tcx, it.def_id, it.span);
|
||||
}
|
||||
hir::ItemKind::Const(..) => {
|
||||
tcx.ensure().typeck(tcx.hir().local_def_id(it.hir_id));
|
||||
tcx.ensure().typeck(it.def_id);
|
||||
}
|
||||
hir::ItemKind::Enum(ref enum_definition, _) => {
|
||||
check_enum(tcx, it.span, &enum_definition.variants, it.hir_id);
|
||||
check_enum(tcx, it.span, &enum_definition.variants, it.def_id);
|
||||
}
|
||||
hir::ItemKind::Fn(..) => {} // entirely within check_item_body
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
debug!("ItemKind::Impl {} with id {}", it.ident, it.hir_id);
|
||||
let impl_def_id = tcx.hir().local_def_id(it.hir_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(impl_def_id) {
|
||||
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.def_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.def_id) {
|
||||
check_impl_items_against_trait(
|
||||
tcx,
|
||||
it.span,
|
||||
impl_def_id,
|
||||
it.def_id,
|
||||
impl_trait_ref,
|
||||
&impl_.items,
|
||||
);
|
||||
|
@ -719,8 +715,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
|||
}
|
||||
}
|
||||
hir::ItemKind::Trait(_, _, _, _, ref items) => {
|
||||
let def_id = tcx.hir().local_def_id(it.hir_id);
|
||||
check_on_unimplemented(tcx, def_id.to_def_id(), it);
|
||||
check_on_unimplemented(tcx, it.def_id.to_def_id(), it);
|
||||
|
||||
for item in items.iter() {
|
||||
let item = tcx.hir().trait_item(item.id);
|
||||
|
@ -730,16 +725,15 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
|||
fn_maybe_err(tcx, item.ident.span, abi);
|
||||
}
|
||||
hir::TraitItemKind::Type(.., Some(_default)) => {
|
||||
let item_def_id = tcx.hir().local_def_id(item.hir_id).to_def_id();
|
||||
let assoc_item = tcx.associated_item(item_def_id);
|
||||
let assoc_item = tcx.associated_item(item.def_id);
|
||||
let trait_substs =
|
||||
InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
|
||||
let _: Result<_, rustc_errors::ErrorReported> = check_type_bounds(
|
||||
tcx,
|
||||
assoc_item,
|
||||
assoc_item,
|
||||
item.span,
|
||||
ty::TraitRef { def_id: def_id.to_def_id(), substs: trait_substs },
|
||||
ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs },
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -747,10 +741,10 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
|||
}
|
||||
}
|
||||
hir::ItemKind::Struct(..) => {
|
||||
check_struct(tcx, it.hir_id, it.span);
|
||||
check_struct(tcx, it.def_id, it.span);
|
||||
}
|
||||
hir::ItemKind::Union(..) => {
|
||||
check_union(tcx, it.hir_id, it.span);
|
||||
check_union(tcx, it.def_id, it.span);
|
||||
}
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
|
||||
// HACK(jynelson): trying to infer the type of `impl trait` breaks documenting
|
||||
|
@ -758,16 +752,13 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
|||
// Since rustdoc doesn't care about the concrete type behind `impl Trait`, just don't look at it!
|
||||
// See https://github.com/rust-lang/rust/issues/75100
|
||||
if !tcx.sess.opts.actually_rustdoc {
|
||||
let def_id = tcx.hir().local_def_id(it.hir_id);
|
||||
|
||||
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
|
||||
check_opaque(tcx, def_id, substs, it.span, &origin);
|
||||
let substs = InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
|
||||
check_opaque(tcx, it.def_id, substs, it.span, &origin);
|
||||
}
|
||||
}
|
||||
hir::ItemKind::TyAlias(..) => {
|
||||
let def_id = tcx.hir().local_def_id(it.hir_id);
|
||||
let pty_ty = tcx.type_of(def_id);
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let pty_ty = tcx.type_of(it.def_id);
|
||||
let generics = tcx.generics_of(it.def_id);
|
||||
check_type_params_are_used(tcx, &generics, pty_ty);
|
||||
}
|
||||
hir::ItemKind::ForeignMod { abi, items } => {
|
||||
|
@ -785,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 {
|
||||
|
@ -835,9 +826,8 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) {
|
|||
}
|
||||
|
||||
pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, trait_def_id: DefId, item: &hir::Item<'_>) {
|
||||
let item_def_id = tcx.hir().local_def_id(item.hir_id);
|
||||
// an error would be reported if this fails.
|
||||
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item_def_id.to_def_id());
|
||||
let _ = traits::OnUnimplementedDirective::of_item(tcx, trait_def_id, item.def_id.to_def_id());
|
||||
}
|
||||
|
||||
pub(super) fn check_specialization_validity<'tcx>(
|
||||
|
@ -938,7 +928,7 @@ pub(super) fn check_impl_items_against_trait<'tcx>(
|
|||
// Check existing impl methods to see if they are both present in trait
|
||||
// and compatible with trait signature
|
||||
for impl_item in impl_items {
|
||||
let ty_impl_item = tcx.associated_item(tcx.hir().local_def_id(impl_item.hir_id));
|
||||
let ty_impl_item = tcx.associated_item(impl_item.def_id);
|
||||
|
||||
let mut items =
|
||||
associated_items.filter_by_name(tcx, ty_impl_item.ident, impl_trait_ref.def_id);
|
||||
|
@ -1345,13 +1335,12 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, sp: Span, adt: &'tcx ty
|
|||
}
|
||||
|
||||
#[allow(trivial_numeric_casts)]
|
||||
pub fn check_enum<'tcx>(
|
||||
fn check_enum<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
sp: Span,
|
||||
vs: &'tcx [hir::Variant<'tcx>],
|
||||
id: hir::HirId,
|
||||
def_id: LocalDefId,
|
||||
) {
|
||||
let def_id = tcx.hir().local_def_id(id);
|
||||
let def = tcx.adt_def(def_id);
|
||||
def.destructor(tcx); // force the destructor to be evaluated
|
||||
|
||||
|
|
|
@ -823,11 +823,11 @@ fn compare_synthetic_generics<'tcx>(
|
|||
// FIXME: this is obviously suboptimal since the name can already be used
|
||||
// as another generic argument
|
||||
let new_name = tcx.sess.source_map().span_to_snippet(trait_span).ok()?;
|
||||
let trait_m = tcx.hir().local_def_id_to_hir_id(trait_m.def_id.as_local()?);
|
||||
let trait_m = tcx.hir().trait_item(hir::TraitItemId { hir_id: trait_m });
|
||||
let trait_m = trait_m.def_id.as_local()?;
|
||||
let trait_m = tcx.hir().trait_item(hir::TraitItemId { def_id: trait_m });
|
||||
|
||||
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
|
||||
|
||||
// in case there are no generics, take the spot between the function name
|
||||
// and the opening paren of the argument list
|
||||
|
@ -860,8 +860,8 @@ fn compare_synthetic_generics<'tcx>(
|
|||
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
|
||||
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
|
||||
(|| {
|
||||
let impl_m = tcx.hir().local_def_id_to_hir_id(impl_m.def_id.as_local()?);
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { hir_id: impl_m });
|
||||
let impl_m = impl_m.def_id.as_local()?;
|
||||
let impl_m = tcx.hir().impl_item(hir::ImplItemId { def_id: impl_m });
|
||||
let input_tys = match impl_m.kind {
|
||||
hir::ImplItemKind::Fn(ref sig, _) => sig.decl.inputs,
|
||||
_ => unreachable!(),
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ use rustc_hir::intravisit;
|
|||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::{ExprKind, Node, QPath};
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
use rustc_middle::hir::map as hir_map;
|
||||
use rustc_middle::ty::fast_reject::simplify_type;
|
||||
use rustc_middle::ty::print::with_crate_prefix;
|
||||
use rustc_middle::ty::{
|
||||
|
@ -1352,17 +1351,15 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
|
|||
|
||||
// Crate-local:
|
||||
|
||||
struct Visitor<'a, 'tcx> {
|
||||
map: &'a hir_map::Map<'tcx>,
|
||||
struct Visitor<'a> {
|
||||
traits: &'a mut Vec<DefId>,
|
||||
}
|
||||
|
||||
impl<'v, 'a, 'tcx> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a, 'tcx> {
|
||||
impl<'v, 'a> itemlikevisit::ItemLikeVisitor<'v> for Visitor<'a> {
|
||||
fn visit_item(&mut self, i: &'v hir::Item<'v>) {
|
||||
match i.kind {
|
||||
hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => {
|
||||
let def_id = self.map.local_def_id(i.hir_id);
|
||||
self.traits.push(def_id.to_def_id());
|
||||
self.traits.push(i.def_id.to_def_id());
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
@ -1375,7 +1372,7 @@ fn compute_all_traits(tcx: TyCtxt<'_>) -> Vec<DefId> {
|
|||
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {}
|
||||
}
|
||||
|
||||
tcx.hir().krate().visit_all_item_likes(&mut Visitor { map: &tcx.hir(), traits: &mut traits });
|
||||
tcx.hir().krate().visit_all_item_likes(&mut Visitor { traits: &mut traits });
|
||||
|
||||
// Cross-crate:
|
||||
|
||||
|
@ -1445,8 +1442,8 @@ impl intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
|
|||
return;
|
||||
}
|
||||
// Find a `use` statement.
|
||||
for item_id in module.item_ids {
|
||||
let item = self.tcx.hir().expect_item(item_id.id);
|
||||
for &item_id in module.item_ids {
|
||||
let item = self.tcx.hir().item(item_id);
|
||||
match item.kind {
|
||||
hir::ItemKind::Use(..) => {
|
||||
// Don't suggest placing a `use` before the prelude
|
||||
|
|
|
@ -80,8 +80,8 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
let item = tcx.hir().expect_item(hir_id);
|
||||
|
||||
debug!(
|
||||
"check_item_well_formed(it.hir_id={:?}, it.name={})",
|
||||
item.hir_id,
|
||||
"check_item_well_formed(it.def_id={:?}, it.name={})",
|
||||
item.def_id,
|
||||
tcx.def_path_str(def_id.to_def_id())
|
||||
);
|
||||
|
||||
|
@ -105,7 +105,7 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
// for `T`
|
||||
hir::ItemKind::Impl(ref impl_) => {
|
||||
let is_auto = tcx
|
||||
.impl_trait_ref(tcx.hir().local_def_id(item.hir_id))
|
||||
.impl_trait_ref(item.def_id)
|
||||
.map_or(false, |trait_ref| tcx.trait_is_auto(trait_ref.def_id));
|
||||
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
|
||||
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);
|
||||
|
@ -141,23 +141,23 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
}
|
||||
}
|
||||
hir::ItemKind::Fn(ref sig, ..) => {
|
||||
check_item_fn(tcx, item.hir_id, item.ident, item.span, sig.decl);
|
||||
check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl);
|
||||
}
|
||||
hir::ItemKind::Static(ref ty, ..) => {
|
||||
check_item_type(tcx, item.hir_id, ty.span, false);
|
||||
check_item_type(tcx, item.hir_id(), ty.span, false);
|
||||
}
|
||||
hir::ItemKind::Const(ref ty, ..) => {
|
||||
check_item_type(tcx, item.hir_id, ty.span, false);
|
||||
check_item_type(tcx, item.hir_id(), ty.span, false);
|
||||
}
|
||||
hir::ItemKind::ForeignMod { items, .. } => {
|
||||
for it in items.iter() {
|
||||
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 => (),
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
_ => None,
|
||||
};
|
||||
check_object_unsafe_self_trait_by_name(tcx, &trait_item);
|
||||
check_associated_item(tcx, trait_item.hir_id, trait_item.span, method_sig);
|
||||
check_associated_item(tcx, trait_item.hir_id(), trait_item.span, method_sig);
|
||||
}
|
||||
|
||||
fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
|
||||
|
@ -213,9 +213,9 @@ fn could_be_self(trait_def_id: LocalDefId, ty: &hir::Ty<'_>) -> bool {
|
|||
/// Detect when an object unsafe trait is referring to itself in one of its associated items.
|
||||
/// When this is done, suggest using `Self` instead.
|
||||
fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem<'_>) {
|
||||
let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id)) {
|
||||
let (trait_name, trait_def_id) = match tcx.hir().get(tcx.hir().get_parent_item(item.hir_id())) {
|
||||
hir::Node::Item(item) => match item.kind {
|
||||
hir::ItemKind::Trait(..) => (item.ident, tcx.hir().local_def_id(item.hir_id)),
|
||||
hir::ItemKind::Trait(..) => (item.ident, item.def_id),
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
|
@ -271,7 +271,7 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
check_associated_item(tcx, impl_item.hir_id, impl_item.span, method_sig);
|
||||
check_associated_item(tcx, impl_item.hir_id(), impl_item.span, method_sig);
|
||||
}
|
||||
|
||||
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
||||
|
@ -432,7 +432,7 @@ fn check_associated_item(
|
|||
}
|
||||
|
||||
fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> {
|
||||
for_id(tcx, item.hir_id, item.span)
|
||||
for_id(tcx, item.hir_id(), item.span)
|
||||
}
|
||||
|
||||
fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> {
|
||||
|
@ -465,8 +465,7 @@ fn check_type_defn<'tcx, F>(
|
|||
{
|
||||
for_item(tcx, item).with_fcx(|fcx, fcx_tcx| {
|
||||
let variants = lookup_fields(fcx);
|
||||
let def_id = fcx.tcx.hir().local_def_id(item.hir_id);
|
||||
let packed = fcx.tcx.adt_def(def_id).repr.packed();
|
||||
let packed = fcx.tcx.adt_def(item.def_id).repr.packed();
|
||||
|
||||
for variant in &variants {
|
||||
// For DST, or when drop needs to copy things around, all
|
||||
|
@ -482,7 +481,7 @@ fn check_type_defn<'tcx, F>(
|
|||
// Just treat unresolved type expression as if it needs drop.
|
||||
true
|
||||
} else {
|
||||
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(def_id))
|
||||
ty.needs_drop(fcx_tcx, fcx_tcx.param_env(item.def_id))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -541,7 +540,7 @@ fn check_type_defn<'tcx, F>(
|
|||
}
|
||||
}
|
||||
|
||||
check_where_clauses(tcx, fcx, item.span, def_id.to_def_id(), None);
|
||||
check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
|
||||
|
||||
// No implied bounds in a struct definition.
|
||||
vec![]
|
||||
|
@ -549,15 +548,13 @@ fn check_type_defn<'tcx, F>(
|
|||
}
|
||||
|
||||
fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
|
||||
debug!("check_trait: {:?}", item.hir_id);
|
||||
debug!("check_trait: {:?}", item.def_id);
|
||||
|
||||
let trait_def_id = tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
let trait_def = tcx.trait_def(trait_def_id);
|
||||
let trait_def = tcx.trait_def(item.def_id);
|
||||
if trait_def.is_marker
|
||||
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
|
||||
{
|
||||
for associated_def_id in &*tcx.associated_item_def_ids(trait_def_id) {
|
||||
for associated_def_id in &*tcx.associated_item_def_ids(item.def_id) {
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
tcx.def_span(*associated_def_id),
|
||||
|
@ -569,7 +566,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
|
|||
}
|
||||
|
||||
for_item(tcx, item).with_fcx(|fcx, _| {
|
||||
check_where_clauses(tcx, fcx, item.span, trait_def_id.to_def_id(), None);
|
||||
check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
|
||||
|
||||
vec![]
|
||||
});
|
||||
|
@ -665,14 +662,12 @@ fn check_impl<'tcx>(
|
|||
debug!("check_impl: {:?}", item);
|
||||
|
||||
for_item(tcx, item).with_fcx(|fcx, tcx| {
|
||||
let item_def_id = fcx.tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
match *ast_trait_ref {
|
||||
Some(ref ast_trait_ref) => {
|
||||
// `#[rustc_reservation_impl]` impls are not real impls and
|
||||
// therefore don't need to be WF (the trait's `Self: Trait` predicate
|
||||
// won't hold).
|
||||
let trait_ref = fcx.tcx.impl_trait_ref(item_def_id).unwrap();
|
||||
let trait_ref = fcx.tcx.impl_trait_ref(item.def_id).unwrap();
|
||||
let trait_ref =
|
||||
fcx.normalize_associated_types_in(ast_trait_ref.path.span, trait_ref);
|
||||
let obligations = traits::wf::trait_obligations(
|
||||
|
@ -688,7 +683,7 @@ fn check_impl<'tcx>(
|
|||
}
|
||||
}
|
||||
None => {
|
||||
let self_ty = fcx.tcx.type_of(item_def_id);
|
||||
let self_ty = fcx.tcx.type_of(item.def_id);
|
||||
let self_ty = fcx.normalize_associated_types_in(item.span, self_ty);
|
||||
fcx.register_wf_obligation(
|
||||
self_ty.into(),
|
||||
|
@ -698,9 +693,9 @@ fn check_impl<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
check_where_clauses(tcx, fcx, item.span, item_def_id.to_def_id(), None);
|
||||
check_where_clauses(tcx, fcx, item.span, item.def_id.to_def_id(), None);
|
||||
|
||||
fcx.impl_implied_bounds(item_def_id.to_def_id(), item.span)
|
||||
fcx.impl_implied_bounds(item.def_id.to_def_id(), item.span)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1238,15 +1233,14 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
item: &hir::Item<'tcx>,
|
||||
hir_generics: &hir::Generics<'_>,
|
||||
) {
|
||||
let item_def_id = tcx.hir().local_def_id(item.hir_id);
|
||||
let ty = tcx.type_of(item_def_id);
|
||||
let ty = tcx.type_of(item.def_id);
|
||||
if tcx.has_error_field(ty) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ty_predicates = tcx.predicates_of(item_def_id);
|
||||
let ty_predicates = tcx.predicates_of(item.def_id);
|
||||
assert_eq!(ty_predicates.parent, None);
|
||||
let variances = tcx.variances_of(item_def_id);
|
||||
let variances = tcx.variances_of(item.def_id);
|
||||
|
||||
let mut constrained_parameters: FxHashSet<_> = variances
|
||||
.iter()
|
||||
|
@ -1354,22 +1348,19 @@ impl Visitor<'tcx> for CheckTypeWellFormedVisitor<'tcx> {
|
|||
|
||||
fn visit_item(&mut self, i: &'tcx hir::Item<'tcx>) {
|
||||
debug!("visit_item: {:?}", i);
|
||||
let def_id = self.tcx.hir().local_def_id(i.hir_id);
|
||||
self.tcx.ensure().check_item_well_formed(def_id);
|
||||
self.tcx.ensure().check_item_well_formed(i.def_id);
|
||||
hir_visit::walk_item(self, i);
|
||||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||
debug!("visit_trait_item: {:?}", trait_item);
|
||||
let def_id = self.tcx.hir().local_def_id(trait_item.hir_id);
|
||||
self.tcx.ensure().check_trait_item_well_formed(def_id);
|
||||
self.tcx.ensure().check_trait_item_well_formed(trait_item.def_id);
|
||||
hir_visit::walk_trait_item(self, trait_item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
debug!("visit_impl_item: {:?}", impl_item);
|
||||
let def_id = self.tcx.hir().local_def_id(impl_item.hir_id);
|
||||
self.tcx.ensure().check_impl_item_well_formed(def_id);
|
||||
self.tcx.ensure().check_impl_item_well_formed(impl_item.def_id);
|
||||
hir_visit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> {
|
|||
return;
|
||||
}
|
||||
if let hir::ItemKind::Use(ref path, _) = item.kind {
|
||||
self.check_import(item.hir_id, path.span);
|
||||
self.check_import(item.item_id(), path.span);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,24 +45,28 @@ struct CheckVisitor<'tcx> {
|
|||
}
|
||||
|
||||
impl CheckVisitor<'tcx> {
|
||||
fn check_import(&self, id: hir::HirId, span: Span) {
|
||||
let def_id = self.tcx.hir().local_def_id(id);
|
||||
if !self.tcx.maybe_unused_trait_import(def_id) {
|
||||
fn check_import(&self, item_id: hir::ItemId, span: Span) {
|
||||
if !self.tcx.maybe_unused_trait_import(item_id.def_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.used_trait_imports.contains(&def_id) {
|
||||
if self.used_trait_imports.contains(&item_id.def_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.tcx.struct_span_lint_hir(lint::builtin::UNUSED_IMPORTS, id, span, |lint| {
|
||||
let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||
format!("unused import: `{}`", snippet)
|
||||
} else {
|
||||
"unused import".to_owned()
|
||||
};
|
||||
lint.build(&msg).emit();
|
||||
});
|
||||
self.tcx.struct_span_lint_hir(
|
||||
lint::builtin::UNUSED_IMPORTS,
|
||||
item_id.hir_id(),
|
||||
span,
|
||||
|lint| {
|
||||
let msg = if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
|
||||
format!("unused import: `{}`", snippet)
|
||||
} else {
|
||||
"unused import".to_owned()
|
||||
};
|
||||
lint.build(&msg).emit();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +113,6 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
|
|||
// Collect all the extern crates (in a reliable order).
|
||||
let mut crates_to_lint = vec![];
|
||||
tcx.hir().krate().visit_all_item_likes(&mut CollectExternCrateVisitor {
|
||||
tcx,
|
||||
crates_to_lint: &mut crates_to_lint,
|
||||
});
|
||||
|
||||
|
@ -189,8 +192,7 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
|
|||
}
|
||||
}
|
||||
|
||||
struct CollectExternCrateVisitor<'a, 'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
struct CollectExternCrateVisitor<'a> {
|
||||
crates_to_lint: &'a mut Vec<ExternCrateToLint>,
|
||||
}
|
||||
|
||||
|
@ -211,12 +213,11 @@ struct ExternCrateToLint {
|
|||
warn_if_unused: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a, 'tcx> {
|
||||
impl<'a, 'v> ItemLikeVisitor<'v> for CollectExternCrateVisitor<'a> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
|
||||
let extern_crate_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
self.crates_to_lint.push(ExternCrateToLint {
|
||||
def_id: extern_crate_def_id.to_def_id(),
|
||||
def_id: item.def_id.to_def_id(),
|
||||
span: item.span,
|
||||
orig_name,
|
||||
warn_if_unused: !item.ident.as_str().starts_with('_'),
|
||||
|
|
|
@ -38,8 +38,7 @@ impl<'tcx> Checker<'tcx> {
|
|||
F: FnMut(TyCtxt<'tcx>, LocalDefId),
|
||||
{
|
||||
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);
|
||||
for &impl_def_id in self.tcx.hir().trait_impls(self.trait_def_id) {
|
||||
f(self.tcx, impl_def_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,8 +50,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
_ => return,
|
||||
};
|
||||
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
let self_ty = self.tcx.type_of(def_id);
|
||||
let self_ty = self.tcx.type_of(item.def_id);
|
||||
let lang_items = self.tcx.lang_items();
|
||||
match *self_ty.kind() {
|
||||
ty::Adt(def, _) => {
|
||||
|
@ -65,7 +64,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Bool => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.bool_impl(),
|
||||
None,
|
||||
"bool",
|
||||
|
@ -76,7 +75,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Char => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.char_impl(),
|
||||
None,
|
||||
"char",
|
||||
|
@ -87,7 +86,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Str => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.str_impl(),
|
||||
lang_items.str_alloc_impl(),
|
||||
"str",
|
||||
|
@ -98,7 +97,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Slice(slice_item) if slice_item == self.tcx.types.u8 => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.slice_u8_impl(),
|
||||
lang_items.slice_u8_alloc_impl(),
|
||||
"slice_u8",
|
||||
|
@ -109,7 +108,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Slice(_) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.slice_impl(),
|
||||
lang_items.slice_alloc_impl(),
|
||||
"slice",
|
||||
|
@ -120,7 +119,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Array(_, _) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.array_impl(),
|
||||
None,
|
||||
"array",
|
||||
|
@ -133,7 +132,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
if matches!(inner.kind(), ty::Slice(_)) =>
|
||||
{
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.const_slice_ptr_impl(),
|
||||
None,
|
||||
"const_slice_ptr",
|
||||
|
@ -146,7 +145,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
if matches!(inner.kind(), ty::Slice(_)) =>
|
||||
{
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.mut_slice_ptr_impl(),
|
||||
None,
|
||||
"mut_slice_ptr",
|
||||
|
@ -157,7 +156,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Not }) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.const_ptr_impl(),
|
||||
None,
|
||||
"const_ptr",
|
||||
|
@ -168,7 +167,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::RawPtr(ty::TypeAndMut { ty: _, mutbl: hir::Mutability::Mut }) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.mut_ptr_impl(),
|
||||
None,
|
||||
"mut_ptr",
|
||||
|
@ -179,7 +178,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::I8) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.i8_impl(),
|
||||
None,
|
||||
"i8",
|
||||
|
@ -190,7 +189,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::I16) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.i16_impl(),
|
||||
None,
|
||||
"i16",
|
||||
|
@ -201,7 +200,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::I32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.i32_impl(),
|
||||
None,
|
||||
"i32",
|
||||
|
@ -212,7 +211,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::I64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.i64_impl(),
|
||||
None,
|
||||
"i64",
|
||||
|
@ -223,7 +222,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::I128) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.i128_impl(),
|
||||
None,
|
||||
"i128",
|
||||
|
@ -234,7 +233,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Int(ty::IntTy::Isize) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.isize_impl(),
|
||||
None,
|
||||
"isize",
|
||||
|
@ -245,7 +244,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::U8) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.u8_impl(),
|
||||
None,
|
||||
"u8",
|
||||
|
@ -256,7 +255,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::U16) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.u16_impl(),
|
||||
None,
|
||||
"u16",
|
||||
|
@ -267,7 +266,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::U32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.u32_impl(),
|
||||
None,
|
||||
"u32",
|
||||
|
@ -278,7 +277,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::U64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.u64_impl(),
|
||||
None,
|
||||
"u64",
|
||||
|
@ -289,7 +288,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::U128) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.u128_impl(),
|
||||
None,
|
||||
"u128",
|
||||
|
@ -300,7 +299,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Uint(ty::UintTy::Usize) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.usize_impl(),
|
||||
None,
|
||||
"usize",
|
||||
|
@ -311,7 +310,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Float(ty::FloatTy::F32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.f32_impl(),
|
||||
lang_items.f32_runtime_impl(),
|
||||
"f32",
|
||||
|
@ -322,7 +321,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
|||
}
|
||||
ty::Float(ty::FloatTy::F64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
item.def_id,
|
||||
lang_items.f64_impl(),
|
||||
lang_items.f64_runtime_impl(),
|
||||
"f64",
|
||||
|
@ -369,9 +368,8 @@ impl InherentCollect<'tcx> {
|
|||
// Add the implementation to the mapping from implementation to base
|
||||
// type def ID, if there is a base type for this implementation and
|
||||
// the implementation does not have any associated traits.
|
||||
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
let vec = self.impls_map.inherent_impls.entry(def_id).or_default();
|
||||
vec.push(impl_def_id.to_def_id());
|
||||
vec.push(item.def_id.to_def_id());
|
||||
} else {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
|
|
@ -123,8 +123,7 @@ impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> {
|
|||
| hir::ItemKind::Struct(..)
|
||||
| hir::ItemKind::Trait(..)
|
||||
| hir::ItemKind::Union(..) => {
|
||||
let ty_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
let impls = self.tcx.inherent_impls(ty_def_id);
|
||||
let impls = self.tcx.inherent_impls(item.def_id);
|
||||
|
||||
// If there is only one inherent impl block,
|
||||
// there is nothing to overlap check it with
|
||||
|
|
|
@ -172,8 +172,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
|
|||
tcx.ensure().specialization_graph_of(def_id);
|
||||
|
||||
let impls = tcx.hir().trait_impls(def_id);
|
||||
for &hir_id in impls {
|
||||
let impl_def_id = tcx.hir().local_def_id(hir_id);
|
||||
for &impl_def_id in impls {
|
||||
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
|
||||
check_impl(tcx, impl_def_id, trait_ref);
|
||||
|
|
|
@ -24,7 +24,6 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
|
|||
/// to prevent inundating the user with a bunch of similar error
|
||||
/// reports.
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
let def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
// "Trait" impl
|
||||
if let hir::ItemKind::Impl(hir::Impl {
|
||||
generics, of_trait: Some(ref tr), self_ty, ..
|
||||
|
@ -32,13 +31,13 @@ impl ItemLikeVisitor<'v> for OrphanChecker<'tcx> {
|
|||
{
|
||||
debug!(
|
||||
"coherence2::orphan check: trait impl {}",
|
||||
self.tcx.hir().node_to_string(item.hir_id)
|
||||
self.tcx.hir().node_to_string(item.hir_id())
|
||||
);
|
||||
let trait_ref = self.tcx.impl_trait_ref(def_id).unwrap();
|
||||
let trait_ref = self.tcx.impl_trait_ref(item.def_id).unwrap();
|
||||
let trait_def_id = trait_ref.def_id;
|
||||
let sm = self.tcx.sess.source_map();
|
||||
let sp = sm.guess_head_span(item.span);
|
||||
match traits::orphan_check(self.tcx, def_id.to_def_id()) {
|
||||
match traits::orphan_check(self.tcx, item.def_id.to_def_id()) {
|
||||
Ok(()) => {}
|
||||
Err(traits::OrphanCheckErr::NonLocalInputType(tys)) => {
|
||||
let mut err = struct_span_err!(
|
||||
|
|
|
@ -24,8 +24,7 @@ impl UnsafetyChecker<'tcx> {
|
|||
unsafety: hir::Unsafety,
|
||||
polarity: hir::ImplPolarity,
|
||||
) {
|
||||
let local_did = self.tcx.hir().local_def_id(item.hir_id);
|
||||
if let Some(trait_ref) = self.tcx.impl_trait_ref(local_did) {
|
||||
if let Some(trait_ref) = self.tcx.impl_trait_ref(item.def_id) {
|
||||
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
||||
let unsafe_attr = impl_generics.and_then(|generics| {
|
||||
generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle")
|
||||
|
|
|
@ -240,7 +240,7 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
convert_item(self.tcx, item.hir_id);
|
||||
convert_item(self.tcx, item.item_id());
|
||||
reject_placeholder_type_signatures_in_item(self.tcx, item);
|
||||
intravisit::walk_item(self, item);
|
||||
}
|
||||
|
@ -274,12 +274,12 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
|
|||
}
|
||||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||
convert_trait_item(self.tcx, trait_item.hir_id);
|
||||
convert_trait_item(self.tcx, trait_item.trait_item_id());
|
||||
intravisit::walk_trait_item(self, trait_item);
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
convert_impl_item(self.tcx, impl_item.hir_id);
|
||||
convert_impl_item(self.tcx, impl_item.impl_item_id());
|
||||
intravisit::walk_impl_item(self, impl_item);
|
||||
}
|
||||
}
|
||||
|
@ -707,10 +707,10 @@ fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty<'_>, param_id: hir::HirId) -> bool
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
|
||||
let it = tcx.hir().expect_item(item_id);
|
||||
debug!("convert: item {} with id {}", it.ident, it.hir_id);
|
||||
let def_id = tcx.hir().local_def_id(item_id);
|
||||
fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
||||
let it = tcx.hir().item(item_id);
|
||||
debug!("convert: item {} with id {}", it.ident, it.hir_id());
|
||||
let def_id = item_id.def_id;
|
||||
|
||||
match it.kind {
|
||||
// These don't define types.
|
||||
|
@ -721,12 +721,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -797,23 +796,22 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
|
||||
let trait_item = tcx.hir().expect_trait_item(trait_item_id);
|
||||
let def_id = tcx.hir().local_def_id(trait_item.hir_id);
|
||||
tcx.ensure().generics_of(def_id);
|
||||
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
||||
let trait_item = tcx.hir().trait_item(trait_item_id);
|
||||
tcx.ensure().generics_of(trait_item_id.def_id);
|
||||
|
||||
match trait_item.kind {
|
||||
hir::TraitItemKind::Fn(..) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
tcx.ensure().type_of(trait_item_id.def_id);
|
||||
tcx.ensure().fn_sig(trait_item_id.def_id);
|
||||
}
|
||||
|
||||
hir::TraitItemKind::Const(.., Some(_)) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().type_of(trait_item_id.def_id);
|
||||
}
|
||||
|
||||
hir::TraitItemKind::Const(..) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().type_of(trait_item_id.def_id);
|
||||
// Account for `const C: _;`.
|
||||
let mut visitor = PlaceholderHirTyCollector::default();
|
||||
visitor.visit_trait_item(trait_item);
|
||||
|
@ -821,8 +819,8 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
|
|||
}
|
||||
|
||||
hir::TraitItemKind::Type(_, Some(_)) => {
|
||||
tcx.ensure().item_bounds(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().item_bounds(trait_item_id.def_id);
|
||||
tcx.ensure().type_of(trait_item_id.def_id);
|
||||
// Account for `type T = _;`.
|
||||
let mut visitor = PlaceholderHirTyCollector::default();
|
||||
visitor.visit_trait_item(trait_item);
|
||||
|
@ -830,7 +828,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
|
|||
}
|
||||
|
||||
hir::TraitItemKind::Type(_, None) => {
|
||||
tcx.ensure().item_bounds(def_id);
|
||||
tcx.ensure().item_bounds(trait_item_id.def_id);
|
||||
// #74612: Visit and try to find bad placeholders
|
||||
// even if there is no concrete type.
|
||||
let mut visitor = PlaceholderHirTyCollector::default();
|
||||
|
@ -840,15 +838,15 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
|
|||
}
|
||||
};
|
||||
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
tcx.ensure().predicates_of(trait_item_id.def_id);
|
||||
}
|
||||
|
||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
|
||||
let def_id = tcx.hir().local_def_id(impl_item_id);
|
||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||
let def_id = impl_item_id.def_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
let impl_item = tcx.hir().expect_impl_item(impl_item_id);
|
||||
let impl_item = tcx.hir().impl_item(impl_item_id);
|
||||
match impl_item.kind {
|
||||
hir::ImplItemKind::Fn(..) => {
|
||||
tcx.ensure().fn_sig(def_id);
|
||||
|
@ -1115,7 +1113,7 @@ fn super_predicates_that_define_assoc_type(
|
|||
let is_trait_alias = tcx.is_trait_alias(trait_def_id);
|
||||
let superbounds2 = icx.type_parameter_bounds_in_generics(
|
||||
generics,
|
||||
item.hir_id,
|
||||
item.hir_id(),
|
||||
self_param_ty,
|
||||
OnlySelfBounds(!is_trait_alias),
|
||||
assoc_name,
|
||||
|
@ -1439,12 +1437,12 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
|
|||
//
|
||||
// Something of a hack: use the node id for the trait, also as
|
||||
// the node id for the Self type parameter.
|
||||
let param_id = item.hir_id;
|
||||
let param_id = item.def_id;
|
||||
|
||||
opt_self = Some(ty::GenericParamDef {
|
||||
index: 0,
|
||||
name: kw::SelfUpper,
|
||||
def_id: tcx.hir().local_def_id(param_id).to_def_id(),
|
||||
def_id: param_id.to_def_id(),
|
||||
pure_wrt_drop: false,
|
||||
kind: ty::GenericParamDefKind::Type {
|
||||
has_default: false,
|
||||
|
|
|
@ -582,26 +582,23 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
|
|||
}
|
||||
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
|
||||
debug!("find_existential_constraints: visiting {:?}", it);
|
||||
let def_id = self.tcx.hir().local_def_id(it.hir_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if def_id.to_def_id() != self.def_id {
|
||||
self.check(def_id);
|
||||
if it.def_id.to_def_id() != self.def_id {
|
||||
self.check(it.def_id);
|
||||
intravisit::walk_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
||||
debug!("find_existential_constraints: visiting {:?}", it);
|
||||
let def_id = self.tcx.hir().local_def_id(it.hir_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if def_id.to_def_id() != self.def_id {
|
||||
self.check(def_id);
|
||||
if it.def_id.to_def_id() != self.def_id {
|
||||
self.check(it.def_id);
|
||||
intravisit::walk_impl_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
|
||||
debug!("find_existential_constraints: visiting {:?}", it);
|
||||
let def_id = self.tcx.hir().local_def_id(it.hir_id);
|
||||
self.check(def_id);
|
||||
self.check(it.def_id);
|
||||
intravisit::walk_trait_item(self, it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
|
|||
// but it's one that we must perform earlier than the rest of
|
||||
// WfCheck.
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_impl_wf(module);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,11 +81,10 @@ struct ImplWfCheck<'tcx> {
|
|||
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
if let hir::ItemKind::Impl(ref impl_) = item.kind {
|
||||
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
enforce_impl_params_are_constrained(self.tcx, impl_def_id, impl_.items);
|
||||
enforce_impl_params_are_constrained(self.tcx, item.def_id, impl_.items);
|
||||
enforce_impl_items_are_distinct(self.tcx, impl_.items);
|
||||
if self.min_specialization {
|
||||
check_min_specialization(self.tcx, impl_def_id.to_def_id(), item.span);
|
||||
check_min_specialization(self.tcx, item.def_id.to_def_id(), item.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +130,7 @@ fn enforce_impl_params_are_constrained(
|
|||
// Disallow unconstrained lifetimes, but only if they appear in assoc types.
|
||||
let lifetimes_in_associated_types: FxHashSet<_> = impl_item_refs
|
||||
.iter()
|
||||
.map(|item_ref| tcx.hir().local_def_id(item_ref.id.hir_id))
|
||||
.map(|item_ref| item_ref.id.def_id)
|
||||
.flat_map(|def_id| {
|
||||
let item = tcx.associated_item(def_id);
|
||||
match item.kind {
|
||||
|
|
|
@ -369,7 +369,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
|
|||
tcx.sess.track_errors(|| {
|
||||
tcx.sess.time("type_collecting", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().collect_mod_item_types(module);
|
||||
}
|
||||
});
|
||||
})?;
|
||||
|
@ -401,7 +401,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {
|
|||
// NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync.
|
||||
tcx.sess.time("item_types_checking", || {
|
||||
for &module in tcx.hir().krate().modules.keys() {
|
||||
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
|
||||
tcx.ensure().check_mod_item_types(module);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_hir::Node;
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
@ -53,16 +52,10 @@ pub struct InferVisitor<'cx, 'tcx> {
|
|||
|
||||
impl<'cx, 'tcx> ItemLikeVisitor<'tcx> for InferVisitor<'cx, 'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
let item_did = self.tcx.hir().local_def_id(item.hir_id);
|
||||
let item_did = item.def_id;
|
||||
|
||||
debug!("InferVisitor::visit_item(item={:?})", item_did);
|
||||
|
||||
let hir_id = self.tcx.hir().local_def_id_to_hir_id(item_did);
|
||||
let item = match self.tcx.hir().get(hir_id) {
|
||||
Node::Item(item) => item,
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
let mut item_required_predicates = RequiredPredicates::default();
|
||||
match item.kind {
|
||||
hir::ItemKind::Union(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) => {
|
||||
|
|
|
@ -14,12 +14,10 @@ struct OutlivesTest<'tcx> {
|
|||
|
||||
impl ItemLikeVisitor<'tcx> for OutlivesTest<'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
// For unit testing: check for a special "rustc_outlives"
|
||||
// attribute and report an error with various results if found.
|
||||
if self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_outlives) {
|
||||
let inferred_outlives_of = self.tcx.inferred_outlives_of(item_def_id);
|
||||
if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_outlives) {
|
||||
let inferred_outlives_of = self.tcx.inferred_outlives_of(item.def_id);
|
||||
struct_span_err!(self.tcx.sess, item.span, E0640, "{:?}", inferred_outlives_of).emit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
match item.kind {
|
||||
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
|
||||
self.visit_node_helper(item.hir_id);
|
||||
self.visit_node_helper(item.hir_id());
|
||||
|
||||
if let hir::VariantData::Tuple(..) = *struct_def {
|
||||
self.visit_node_helper(struct_def.ctor_hir_id().unwrap());
|
||||
|
@ -79,7 +79,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ItemKind::Enum(ref enum_def, _) => {
|
||||
self.visit_node_helper(item.hir_id);
|
||||
self.visit_node_helper(item.hir_id());
|
||||
|
||||
for variant in enum_def.variants {
|
||||
if let hir::VariantData::Tuple(..) = variant.data {
|
||||
|
@ -89,7 +89,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ItemKind::Fn(..) => {
|
||||
self.visit_node_helper(item.hir_id);
|
||||
self.visit_node_helper(item.hir_id());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
@ -98,19 +98,19 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ConstraintContext<'a, 'tcx> {
|
|||
|
||||
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
|
||||
self.visit_node_helper(trait_item.hir_id);
|
||||
self.visit_node_helper(trait_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
|
||||
self.visit_node_helper(impl_item.hir_id);
|
||||
self.visit_node_helper(impl_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,11 +128,11 @@ impl<'a, 'tcx> TermsContext<'a, 'tcx> {
|
|||
|
||||
impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
|
||||
fn visit_item(&mut self, item: &hir::Item<'_>) {
|
||||
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id));
|
||||
debug!("add_inferreds for item {}", self.tcx.hir().node_to_string(item.hir_id()));
|
||||
|
||||
match item.kind {
|
||||
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
|
||||
self.add_inferreds_for_item(item.hir_id);
|
||||
self.add_inferreds_for_item(item.hir_id());
|
||||
|
||||
if let hir::VariantData::Tuple(..) = *struct_def {
|
||||
self.add_inferreds_for_item(struct_def.ctor_hir_id().unwrap());
|
||||
|
@ -140,7 +140,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ItemKind::Enum(ref enum_def, _) => {
|
||||
self.add_inferreds_for_item(item.hir_id);
|
||||
self.add_inferreds_for_item(item.hir_id());
|
||||
|
||||
for variant in enum_def.variants {
|
||||
if let hir::VariantData::Tuple(..) = variant.data {
|
||||
|
@ -150,7 +150,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
hir::ItemKind::Fn(..) => {
|
||||
self.add_inferreds_for_item(item.hir_id);
|
||||
self.add_inferreds_for_item(item.hir_id());
|
||||
}
|
||||
|
||||
_ => {}
|
||||
|
@ -159,19 +159,19 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for TermsContext<'a, 'tcx> {
|
|||
|
||||
fn visit_trait_item(&mut self, trait_item: &hir::TraitItem<'_>) {
|
||||
if let hir::TraitItemKind::Fn(..) = trait_item.kind {
|
||||
self.add_inferreds_for_item(trait_item.hir_id);
|
||||
self.add_inferreds_for_item(trait_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
|
||||
if let hir::ImplItemKind::Fn(..) = impl_item.kind {
|
||||
self.add_inferreds_for_item(impl_item.hir_id);
|
||||
self.add_inferreds_for_item(impl_item.hir_id());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,12 +14,10 @@ struct VarianceTest<'tcx> {
|
|||
|
||||
impl ItemLikeVisitor<'tcx> for VarianceTest<'tcx> {
|
||||
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
|
||||
let item_def_id = self.tcx.hir().local_def_id(item.hir_id);
|
||||
|
||||
// For unit testing: check for a special "rustc_variance"
|
||||
// attribute and report an error with various results if found.
|
||||
if self.tcx.has_attr(item_def_id.to_def_id(), sym::rustc_variance) {
|
||||
let variances_of = self.tcx.variances_of(item_def_id);
|
||||
if self.tcx.has_attr(item.def_id.to_def_id(), sym::rustc_variance) {
|
||||
let variances_of = self.tcx.variances_of(item.def_id);
|
||||
struct_span_err!(self.tcx.sess, item.span, E0208, "{:?}", variances_of).emit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue