Rename some OwnerId
fields.
spastorino noticed some silly expressions like `item_id.def_id.def_id`. This commit renames several `def_id: OwnerId` fields as `owner_id`, so those expressions become `item_id.owner_id.def_id`. `item_id.owner_id.local_def_id` would be even clearer, but the use of `def_id` for values of type `LocalDefId` is *very* widespread, so I left that alone.
This commit is contained in:
parent
33b55ac39f
commit
c8c25ce5a1
107 changed files with 618 additions and 603 deletions
|
@ -2661,7 +2661,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}
|
||||
hir::TyKind::OpaqueDef(item_id, lifetimes, in_trait) => {
|
||||
let opaque_ty = tcx.hir().item(item_id);
|
||||
let def_id = item_id.def_id.to_def_id();
|
||||
let def_id = item_id.owner_id.to_def_id();
|
||||
|
||||
match opaque_ty.kind {
|
||||
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => {
|
||||
|
|
|
@ -227,17 +227,17 @@ fn check_opaque<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
return;
|
||||
}
|
||||
|
||||
let substs = InternalSubsts::identity_for_item(tcx, item.def_id.to_def_id());
|
||||
let span = tcx.def_span(item.def_id.def_id);
|
||||
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id.to_def_id());
|
||||
let span = tcx.def_span(item.owner_id.def_id);
|
||||
|
||||
check_opaque_for_inheriting_lifetimes(tcx, item.def_id.def_id, span);
|
||||
if tcx.type_of(item.def_id.def_id).references_error() {
|
||||
check_opaque_for_inheriting_lifetimes(tcx, item.owner_id.def_id, span);
|
||||
if tcx.type_of(item.owner_id.def_id).references_error() {
|
||||
return;
|
||||
}
|
||||
if check_opaque_for_cycles(tcx, item.def_id.def_id, substs, span, &origin).is_err() {
|
||||
if check_opaque_for_cycles(tcx, item.owner_id.def_id, substs, span, &origin).is_err() {
|
||||
return;
|
||||
}
|
||||
check_opaque_meets_bounds(tcx, item.def_id.def_id, substs, span, &origin);
|
||||
check_opaque_meets_bounds(tcx, item.owner_id.def_id, substs, span, &origin);
|
||||
}
|
||||
/// Checks that an opaque type does not use `Self` or `T::Foo` projections that would result
|
||||
/// in "inheriting lifetimes".
|
||||
|
@ -492,25 +492,25 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||
fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
||||
debug!(
|
||||
"check_item_type(it.def_id={:?}, it.name={})",
|
||||
id.def_id,
|
||||
tcx.def_path_str(id.def_id.to_def_id())
|
||||
id.owner_id,
|
||||
tcx.def_path_str(id.owner_id.to_def_id())
|
||||
);
|
||||
let _indenter = indenter();
|
||||
match tcx.def_kind(id.def_id) {
|
||||
match tcx.def_kind(id.owner_id) {
|
||||
DefKind::Static(..) => {
|
||||
tcx.ensure().typeck(id.def_id.def_id);
|
||||
maybe_check_static_with_link_section(tcx, id.def_id.def_id);
|
||||
check_static_inhabited(tcx, id.def_id.def_id);
|
||||
tcx.ensure().typeck(id.owner_id.def_id);
|
||||
maybe_check_static_with_link_section(tcx, id.owner_id.def_id);
|
||||
check_static_inhabited(tcx, id.owner_id.def_id);
|
||||
}
|
||||
DefKind::Const => {
|
||||
tcx.ensure().typeck(id.def_id.def_id);
|
||||
tcx.ensure().typeck(id.owner_id.def_id);
|
||||
}
|
||||
DefKind::Enum => {
|
||||
let item = tcx.hir().item(id);
|
||||
let hir::ItemKind::Enum(ref enum_definition, _) = item.kind else {
|
||||
return;
|
||||
};
|
||||
check_enum(tcx, &enum_definition.variants, item.def_id.def_id);
|
||||
check_enum(tcx, &enum_definition.variants, item.owner_id.def_id);
|
||||
}
|
||||
DefKind::Fn => {} // entirely within check_item_body
|
||||
DefKind::Impl => {
|
||||
|
@ -518,12 +518,12 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
let hir::ItemKind::Impl(ref impl_) = it.kind else {
|
||||
return;
|
||||
};
|
||||
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.def_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.def_id) {
|
||||
debug!("ItemKind::Impl {} with id {:?}", it.ident, it.owner_id);
|
||||
if let Some(impl_trait_ref) = tcx.impl_trait_ref(it.owner_id) {
|
||||
check_impl_items_against_trait(
|
||||
tcx,
|
||||
it.span,
|
||||
it.def_id.def_id,
|
||||
it.owner_id.def_id,
|
||||
impl_trait_ref,
|
||||
&impl_.items,
|
||||
);
|
||||
|
@ -545,15 +545,15 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
fn_maybe_err(tcx, item.ident.span, abi);
|
||||
}
|
||||
hir::TraitItemKind::Type(.., Some(default)) => {
|
||||
let assoc_item = tcx.associated_item(item.def_id);
|
||||
let assoc_item = tcx.associated_item(item.owner_id);
|
||||
let trait_substs =
|
||||
InternalSubsts::identity_for_item(tcx, it.def_id.to_def_id());
|
||||
InternalSubsts::identity_for_item(tcx, it.owner_id.to_def_id());
|
||||
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
|
||||
tcx,
|
||||
assoc_item,
|
||||
assoc_item,
|
||||
default.span,
|
||||
ty::TraitRef { def_id: it.def_id.to_def_id(), substs: trait_substs },
|
||||
ty::TraitRef { def_id: it.owner_id.to_def_id(), substs: trait_substs },
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
|
@ -561,16 +561,16 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
}
|
||||
}
|
||||
DefKind::Struct => {
|
||||
check_struct(tcx, id.def_id.def_id);
|
||||
check_struct(tcx, id.owner_id.def_id);
|
||||
}
|
||||
DefKind::Union => {
|
||||
check_union(tcx, id.def_id.def_id);
|
||||
check_union(tcx, id.owner_id.def_id);
|
||||
}
|
||||
DefKind::OpaqueTy => {
|
||||
check_opaque(tcx, id);
|
||||
}
|
||||
DefKind::ImplTraitPlaceholder => {
|
||||
let parent = tcx.impl_trait_in_trait_parent(id.def_id.to_def_id());
|
||||
let parent = tcx.impl_trait_in_trait_parent(id.owner_id.to_def_id());
|
||||
// Only check the validity of this opaque type if the function has a default body
|
||||
if let hir::Node::TraitItem(hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)),
|
||||
|
@ -581,8 +581,8 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
}
|
||||
}
|
||||
DefKind::TyAlias => {
|
||||
let pty_ty = tcx.type_of(id.def_id);
|
||||
let generics = tcx.generics_of(id.def_id);
|
||||
let pty_ty = tcx.type_of(id.owner_id);
|
||||
let generics = tcx.generics_of(id.owner_id);
|
||||
check_type_params_are_used(tcx, &generics, pty_ty);
|
||||
}
|
||||
DefKind::ForeignMod => {
|
||||
|
@ -604,7 +604,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
}
|
||||
} else {
|
||||
for item in items {
|
||||
let def_id = item.id.def_id.def_id;
|
||||
let def_id = item.id.owner_id.def_id;
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let own_counts = generics.own_counts();
|
||||
if generics.params.len() - own_counts.lifetimes != 0 {
|
||||
|
@ -659,7 +659,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) {
|
|||
|
||||
pub(super) fn check_on_unimplemented(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
|
||||
// an error would be reported if this fails.
|
||||
let _ = traits::OnUnimplementedDirective::of_item(tcx, item.def_id.to_def_id());
|
||||
let _ = traits::OnUnimplementedDirective::of_item(tcx, item.owner_id.to_def_id());
|
||||
}
|
||||
|
||||
pub(super) fn check_specialization_validity<'tcx>(
|
||||
|
@ -746,7 +746,7 @@ fn check_impl_items_against_trait<'tcx>(
|
|||
let trait_def = tcx.trait_def(impl_trait_ref.def_id);
|
||||
|
||||
for impl_item in impl_item_refs {
|
||||
let ty_impl_item = tcx.associated_item(impl_item.id.def_id);
|
||||
let ty_impl_item = tcx.associated_item(impl_item.id.owner_id);
|
||||
let ty_trait_item = if let Some(trait_item_id) = ty_impl_item.trait_item_def_id {
|
||||
tcx.associated_item(trait_item_id)
|
||||
} else {
|
||||
|
@ -758,7 +758,7 @@ fn check_impl_items_against_trait<'tcx>(
|
|||
match impl_item_full.kind {
|
||||
hir::ImplItemKind::Const(..) => {
|
||||
let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
|
||||
impl_item.id.def_id.def_id,
|
||||
impl_item.id.owner_id.def_id,
|
||||
ty_impl_item.trait_item_def_id.unwrap(),
|
||||
));
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ fn equate_intrinsic_type<'tcx>(
|
|||
) {
|
||||
let (own_counts, span) = match &it.kind {
|
||||
hir::ForeignItemKind::Fn(.., generics) => {
|
||||
let own_counts = tcx.generics_of(it.def_id.to_def_id()).own_counts();
|
||||
let own_counts = tcx.generics_of(it.owner_id.to_def_id()).own_counts();
|
||||
(own_counts, generics.span)
|
||||
}
|
||||
_ => {
|
||||
|
@ -57,7 +57,7 @@ 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(it.def_id)), fty);
|
||||
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id)), fty);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ pub fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: DefId) -> hir
|
|||
/// 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 intrinsic_id = it.def_id.to_def_id();
|
||||
let intrinsic_id = it.owner_id.to_def_id();
|
||||
let intrinsic_name = tcx.item_name(intrinsic_id);
|
||||
let name_str = intrinsic_name.as_str();
|
||||
|
||||
|
|
|
@ -147,10 +147,10 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) {
|
|||
/// the types first.
|
||||
#[instrument(skip(tcx), level = "debug")]
|
||||
fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||
let def_id = item.def_id.def_id;
|
||||
let def_id = item.owner_id.def_id;
|
||||
|
||||
debug!(
|
||||
?item.def_id,
|
||||
?item.owner_id,
|
||||
item.name = ? tcx.def_path_str(def_id.to_def_id())
|
||||
);
|
||||
|
||||
|
@ -246,10 +246,10 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||
}
|
||||
|
||||
fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) {
|
||||
let def_id = item.def_id.def_id;
|
||||
let def_id = item.owner_id.def_id;
|
||||
|
||||
debug!(
|
||||
?item.def_id,
|
||||
?item.owner_id,
|
||||
item.name = ? tcx.def_path_str(def_id.to_def_id())
|
||||
);
|
||||
|
||||
|
@ -263,7 +263,7 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) {
|
|||
}
|
||||
|
||||
fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
|
||||
let def_id = trait_item.def_id.def_id;
|
||||
let def_id = trait_item.owner_id.def_id;
|
||||
|
||||
let (method_sig, span) = match trait_item.kind {
|
||||
hir::TraitItemKind::Fn(ref sig, _) => (Some(sig), trait_item.span),
|
||||
|
@ -275,7 +275,7 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) {
|
|||
|
||||
let encl_trait_def_id = tcx.local_parent(def_id);
|
||||
let encl_trait = tcx.hir().expect_item(encl_trait_def_id);
|
||||
let encl_trait_def_id = encl_trait.def_id.to_def_id();
|
||||
let encl_trait_def_id = encl_trait.owner_id.to_def_id();
|
||||
let fn_lang_item_name = if Some(encl_trait_def_id) == tcx.lang_items().fn_trait() {
|
||||
Some("fn")
|
||||
} else if Some(encl_trait_def_id) == tcx.lang_items().fn_mut_trait() {
|
||||
|
@ -348,7 +348,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
loop {
|
||||
let mut should_continue = false;
|
||||
for gat_item in associated_items {
|
||||
let gat_def_id = gat_item.id.def_id;
|
||||
let gat_def_id = gat_item.id.owner_id;
|
||||
let gat_item = tcx.associated_item(gat_def_id);
|
||||
// If this item is not an assoc ty, or has no substs, then it's not a GAT
|
||||
if gat_item.kind != ty::AssocKind::Type {
|
||||
|
@ -365,7 +365,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
|
|||
// constrains the GAT with individually.
|
||||
let mut new_required_bounds: Option<FxHashSet<ty::Predicate<'_>>> = None;
|
||||
for item in associated_items {
|
||||
let item_def_id = item.id.def_id;
|
||||
let item_def_id = item.id.owner_id;
|
||||
// Skip our own GAT, since it does not constrain itself at all.
|
||||
if item_def_id == gat_def_id {
|
||||
continue;
|
||||
|
@ -790,7 +790,7 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
|
|||
let (trait_name, trait_def_id) =
|
||||
match tcx.hir().get_by_def_id(tcx.hir().get_parent_item(item.hir_id()).def_id) {
|
||||
hir::Node::Item(item) => match item.kind {
|
||||
hir::ItemKind::Trait(..) => (item.ident, item.def_id),
|
||||
hir::ItemKind::Trait(..) => (item.ident, item.owner_id),
|
||||
_ => return,
|
||||
},
|
||||
_ => return,
|
||||
|
@ -845,7 +845,7 @@ fn check_impl_item(tcx: TyCtxt<'_>, impl_item: &hir::ImplItem<'_>) {
|
|||
_ => (None, impl_item.span),
|
||||
};
|
||||
|
||||
check_associated_item(tcx, impl_item.def_id.def_id, span, method_sig);
|
||||
check_associated_item(tcx, impl_item.owner_id.def_id, span, method_sig);
|
||||
}
|
||||
|
||||
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
|
||||
|
@ -1045,11 +1045,11 @@ fn check_type_defn<'tcx, F>(
|
|||
) where
|
||||
F: FnMut(&WfCheckingCtxt<'_, 'tcx>) -> Vec<AdtVariant<'tcx>>,
|
||||
{
|
||||
let _ = tcx.representability(item.def_id.def_id);
|
||||
let _ = tcx.representability(item.owner_id.def_id);
|
||||
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.def_id.def_id, |wfcx| {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
|
||||
let variants = lookup_fields(wfcx);
|
||||
let packed = tcx.adt_def(item.def_id).repr().packed();
|
||||
let packed = tcx.adt_def(item.owner_id).repr().packed();
|
||||
|
||||
for variant in &variants {
|
||||
// All field types must be well-formed.
|
||||
|
@ -1073,7 +1073,7 @@ fn check_type_defn<'tcx, F>(
|
|||
// Just treat unresolved type expression as if it needs drop.
|
||||
true
|
||||
} else {
|
||||
ty.needs_drop(tcx, tcx.param_env(item.def_id))
|
||||
ty.needs_drop(tcx, tcx.param_env(item.owner_id))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -1121,15 +1121,15 @@ fn check_type_defn<'tcx, F>(
|
|||
}
|
||||
}
|
||||
|
||||
check_where_clauses(wfcx, item.span, item.def_id.def_id);
|
||||
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
|
||||
});
|
||||
}
|
||||
|
||||
#[instrument(skip(tcx, item))]
|
||||
fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
|
||||
debug!(?item.def_id);
|
||||
debug!(?item.owner_id);
|
||||
|
||||
let def_id = item.def_id.def_id;
|
||||
let def_id = item.owner_id.def_id;
|
||||
let trait_def = tcx.trait_def(def_id);
|
||||
if trait_def.is_marker
|
||||
|| matches!(trait_def.specialization_kind, TraitSpecializationKind::Marker)
|
||||
|
@ -1240,13 +1240,13 @@ fn check_impl<'tcx>(
|
|||
ast_trait_ref: &Option<hir::TraitRef<'_>>,
|
||||
constness: hir::Constness,
|
||||
) {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.def_id.def_id, |wfcx| {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
|
||||
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 = tcx.impl_trait_ref(item.def_id).unwrap();
|
||||
let trait_ref = tcx.impl_trait_ref(item.owner_id).unwrap();
|
||||
let trait_ref = wfcx.normalize(ast_trait_ref.path.span, None, trait_ref);
|
||||
let trait_pred = ty::TraitPredicate {
|
||||
trait_ref,
|
||||
|
@ -1268,7 +1268,7 @@ fn check_impl<'tcx>(
|
|||
wfcx.register_obligations(obligations);
|
||||
}
|
||||
None => {
|
||||
let self_ty = tcx.type_of(item.def_id);
|
||||
let self_ty = tcx.type_of(item.owner_id);
|
||||
let self_ty = wfcx.normalize(
|
||||
item.span,
|
||||
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
||||
|
@ -1282,7 +1282,7 @@ fn check_impl<'tcx>(
|
|||
}
|
||||
}
|
||||
|
||||
check_where_clauses(wfcx, item.span, item.def_id.def_id);
|
||||
check_where_clauses(wfcx, item.span, item.owner_id.def_id);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1778,14 +1778,14 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
item: &hir::Item<'tcx>,
|
||||
hir_generics: &hir::Generics<'_>,
|
||||
) {
|
||||
let ty = tcx.type_of(item.def_id);
|
||||
let ty = tcx.type_of(item.owner_id);
|
||||
if tcx.has_error_field(ty) {
|
||||
return;
|
||||
}
|
||||
|
||||
let ty_predicates = tcx.predicates_of(item.def_id);
|
||||
let ty_predicates = tcx.predicates_of(item.owner_id);
|
||||
assert_eq!(ty_predicates.parent, None);
|
||||
let variances = tcx.variances_of(item.def_id);
|
||||
let variances = tcx.variances_of(item.owner_id);
|
||||
|
||||
let mut constrained_parameters: FxHashSet<_> = variances
|
||||
.iter()
|
||||
|
@ -1798,7 +1798,7 @@ fn check_variances_for_type_defn<'tcx>(
|
|||
|
||||
// Lazily calculated because it is only needed in case of an error.
|
||||
let explicitly_bounded_params = LazyCell::new(|| {
|
||||
let icx = crate::collect::ItemCtxt::new(tcx, item.def_id.to_def_id());
|
||||
let icx = crate::collect::ItemCtxt::new(tcx, item.owner_id.to_def_id());
|
||||
hir_generics
|
||||
.predicates
|
||||
.iter()
|
||||
|
@ -1919,10 +1919,10 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||
|
||||
fn check_mod_type_wf(tcx: TyCtxt<'_>, module: LocalDefId) {
|
||||
let items = tcx.hir_module_items(module);
|
||||
items.par_items(|item| tcx.ensure().check_well_formed(item.def_id));
|
||||
items.par_impl_items(|item| tcx.ensure().check_well_formed(item.def_id));
|
||||
items.par_trait_items(|item| tcx.ensure().check_well_formed(item.def_id));
|
||||
items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.def_id));
|
||||
items.par_items(|item| tcx.ensure().check_well_formed(item.owner_id));
|
||||
items.par_impl_items(|item| tcx.ensure().check_well_formed(item.owner_id));
|
||||
items.par_trait_items(|item| tcx.ensure().check_well_formed(item.owner_id));
|
||||
items.par_foreign_items(|item| tcx.ensure().check_well_formed(item.owner_id));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -89,11 +89,11 @@ fn unused_crates_lint(tcx: TyCtxt<'_>) {
|
|||
let mut crates_to_lint = vec![];
|
||||
|
||||
for id in tcx.hir().items() {
|
||||
if matches!(tcx.def_kind(id.def_id), DefKind::ExternCrate) {
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::ExternCrate) {
|
||||
let item = tcx.hir().item(id);
|
||||
if let hir::ItemKind::ExternCrate(orig_name) = item.kind {
|
||||
crates_to_lint.push(ExternCrateToLint {
|
||||
def_id: item.def_id.to_def_id(),
|
||||
def_id: item.owner_id.to_def_id(),
|
||||
span: item.span,
|
||||
orig_name,
|
||||
warn_if_unused: !item.ident.as_str().starts_with('_'),
|
||||
|
|
|
@ -58,7 +58,7 @@ const ADD_ATTR: &str =
|
|||
|
||||
impl<'tcx> InherentCollect<'tcx> {
|
||||
fn check_def_id(&mut self, item: &hir::Item<'_>, self_ty: Ty<'tcx>, def_id: DefId) {
|
||||
let impl_def_id = item.def_id;
|
||||
let impl_def_id = item.owner_id;
|
||||
if let Some(def_id) = def_id.as_local() {
|
||||
// Add the implementation to the mapping from implementation to base
|
||||
// type def ID, if there is a base type for this implementation and
|
||||
|
@ -89,7 +89,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
for impl_item in items {
|
||||
if !self
|
||||
.tcx
|
||||
.has_attr(impl_item.id.def_id.to_def_id(), sym::rustc_allow_incoherent_impl)
|
||||
.has_attr(impl_item.id.owner_id.to_def_id(), sym::rustc_allow_incoherent_impl)
|
||||
{
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
@ -135,7 +135,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
for item in items {
|
||||
if !self
|
||||
.tcx
|
||||
.has_attr(item.id.def_id.to_def_id(), sym::rustc_allow_incoherent_impl)
|
||||
.has_attr(item.id.owner_id.to_def_id(), sym::rustc_allow_incoherent_impl)
|
||||
{
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
|
@ -177,7 +177,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
}
|
||||
|
||||
fn check_item(&mut self, id: hir::ItemId) {
|
||||
if !matches!(self.tcx.def_kind(id.def_id), DefKind::Impl) {
|
||||
if !matches!(self.tcx.def_kind(id.owner_id), DefKind::Impl) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
return;
|
||||
};
|
||||
|
||||
let self_ty = self.tcx.type_of(item.def_id);
|
||||
let self_ty = self.tcx.type_of(item.owner_id);
|
||||
match *self_ty.kind() {
|
||||
ty::Adt(def, _) => {
|
||||
self.check_def_id(item, self_ty, def.did());
|
||||
|
@ -221,7 +221,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
| ty::Never
|
||||
| ty::FnPtr(_)
|
||||
| ty::Tuple(..) => {
|
||||
self.check_primitive_impl(item.def_id.def_id, self_ty, items, ty.span)
|
||||
self.check_primitive_impl(item.owner_id.def_id, self_ty, items, ty.span)
|
||||
}
|
||||
ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => {
|
||||
let mut err = struct_span_err!(
|
||||
|
@ -243,7 +243,7 @@ impl<'tcx> InherentCollect<'tcx> {
|
|||
| ty::Bound(..)
|
||||
| ty::Placeholder(_)
|
||||
| ty::Infer(_) => {
|
||||
bug!("unexpected impl self type of impl: {:?} {:?}", item.def_id, self_ty);
|
||||
bug!("unexpected impl self type of impl: {:?} {:?}", item.owner_id, self_ty);
|
||||
}
|
||||
ty::Error(_) => {}
|
||||
}
|
||||
|
|
|
@ -156,14 +156,14 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
|
|||
}
|
||||
|
||||
fn check_item(&mut self, id: hir::ItemId) {
|
||||
let def_kind = self.tcx.def_kind(id.def_id);
|
||||
let def_kind = self.tcx.def_kind(id.owner_id);
|
||||
if !matches!(def_kind, DefKind::Enum | DefKind::Struct | DefKind::Trait | DefKind::Union) {
|
||||
return;
|
||||
}
|
||||
|
||||
let impls = self.tcx.inherent_impls(id.def_id);
|
||||
let impls = self.tcx.inherent_impls(id.owner_id);
|
||||
|
||||
let overlap_mode = OverlapMode::get(self.tcx, id.def_id.to_def_id());
|
||||
let overlap_mode = OverlapMode::get(self.tcx, id.owner_id.to_def_id());
|
||||
|
||||
let impls_items = impls
|
||||
.iter()
|
||||
|
|
|
@ -101,7 +101,7 @@ fn do_orphan_check_impl<'tcx>(
|
|||
span_bug!(sp, "opaque type not found, but `has_opaque_types` is set")
|
||||
}
|
||||
|
||||
match traits::orphan_check(tcx, item.def_id.to_def_id()) {
|
||||
match traits::orphan_check(tcx, item.owner_id.to_def_id()) {
|
||||
Ok(()) => {}
|
||||
Err(err) => emit_orphan_check_error(
|
||||
tcx,
|
||||
|
|
|
@ -13,7 +13,7 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
|
|||
let item = tcx.hir().expect_item(def_id);
|
||||
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
|
||||
|
||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.def_id) {
|
||||
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
|
||||
let trait_def = tcx.trait_def(trait_ref.def_id);
|
||||
let unsafe_attr =
|
||||
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
|
||||
|
|
|
@ -571,7 +571,7 @@ fn get_new_lifetime_name<'tcx>(
|
|||
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.def_id;
|
||||
let def_id = item_id.owner_id.def_id;
|
||||
|
||||
match it.kind {
|
||||
// These don't define types.
|
||||
|
@ -583,11 +583,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);
|
||||
tcx.ensure().generics_of(item.def_id);
|
||||
tcx.ensure().type_of(item.def_id);
|
||||
tcx.ensure().predicates_of(item.def_id);
|
||||
tcx.ensure().generics_of(item.owner_id);
|
||||
tcx.ensure().type_of(item.owner_id);
|
||||
tcx.ensure().predicates_of(item.owner_id);
|
||||
match item.kind {
|
||||
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.def_id),
|
||||
hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.owner_id),
|
||||
hir::ForeignItemKind::Static(..) => {
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_foreign_item(item);
|
||||
|
@ -683,7 +683,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||
|
||||
fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
||||
let trait_item = tcx.hir().trait_item(trait_item_id);
|
||||
let def_id = trait_item_id.def_id;
|
||||
let def_id = trait_item_id.owner_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
|
||||
match trait_item.kind {
|
||||
|
@ -730,7 +730,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
}
|
||||
|
||||
fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
||||
let def_id = impl_item_id.def_id;
|
||||
let def_id = impl_item_id.owner_id;
|
||||
tcx.ensure().generics_of(def_id);
|
||||
tcx.ensure().type_of(def_id);
|
||||
tcx.ensure().predicates_of(def_id);
|
||||
|
@ -1010,7 +1010,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
|
|||
|
||||
match item {
|
||||
Some(item) if matches!(item.kind, hir::AssocItemKind::Fn { .. }) => {
|
||||
if !tcx.impl_defaultness(item.id.def_id).has_value() {
|
||||
if !tcx.impl_defaultness(item.id.owner_id).has_value() {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
item.span,
|
||||
|
|
|
@ -331,8 +331,8 @@ fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetime
|
|||
/// `resolve_lifetimes`.
|
||||
fn resolve_lifetimes_for<'tcx>(tcx: TyCtxt<'tcx>, def_id: hir::OwnerId) -> &'tcx ResolveLifetimes {
|
||||
let item_id = item_for(tcx, def_id.def_id);
|
||||
let local_def_id = item_id.def_id.def_id;
|
||||
if item_id.def_id == def_id {
|
||||
let local_def_id = item_id.owner_id.def_id;
|
||||
if item_id.owner_id == def_id {
|
||||
let item = tcx.hir().item(item_id);
|
||||
match item.kind {
|
||||
hir::ItemKind::Trait(..) => tcx.resolve_lifetimes_trait_definition(local_def_id),
|
||||
|
@ -557,11 +557,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
// their owner, we can keep going until we find the Item that owns that. We then
|
||||
// conservatively add all resolved lifetimes. Otherwise we run into problems in
|
||||
// cases like `type Foo<'a> = impl Bar<As = impl Baz + 'a>`.
|
||||
for (_hir_id, node) in self.tcx.hir().parent_iter(item.def_id.into()) {
|
||||
for (_hir_id, node) in self.tcx.hir().parent_iter(item.owner_id.into()) {
|
||||
match node {
|
||||
hir::Node::Item(parent_item) => {
|
||||
let resolved_lifetimes: &ResolveLifetimes = self.tcx.resolve_lifetimes(
|
||||
item_for(self.tcx, parent_item.def_id.def_id).def_id.def_id,
|
||||
item_for(self.tcx, parent_item.owner_id.def_id).owner_id.def_id,
|
||||
);
|
||||
// We need to add *all* deps, since opaque tys may want them from *us*
|
||||
for (&owner, defs) in resolved_lifetimes.defs.iter() {
|
||||
|
|
|
@ -643,24 +643,24 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
|
|||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.def_id.def_id != self.def_id {
|
||||
self.check(it.def_id.def_id);
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.def_id.def_id != self.def_id {
|
||||
self.check(it.def_id.def_id);
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_impl_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
self.check(it.def_id.def_id);
|
||||
trace!(?it.owner_id);
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_trait_item(self, it);
|
||||
}
|
||||
}
|
||||
|
@ -772,24 +772,24 @@ fn find_opaque_ty_constraints_for_rpit(
|
|||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
fn visit_item(&mut self, it: &'tcx Item<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.def_id.def_id != self.def_id {
|
||||
self.check(it.def_id.def_id);
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.def_id.def_id != self.def_id {
|
||||
self.check(it.def_id.def_id);
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_impl_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
|
||||
trace!(?it.def_id);
|
||||
self.check(it.def_id.def_id);
|
||||
trace!(?it.owner_id);
|
||||
self.check(it.owner_id.def_id);
|
||||
intravisit::walk_trait_item(self, it);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,10 +55,10 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
|
|||
let min_specialization = tcx.features().min_specialization;
|
||||
let module = tcx.hir_module_items(module_def_id);
|
||||
for id in module.items() {
|
||||
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
|
||||
enforce_impl_params_are_constrained(tcx, id.def_id.def_id);
|
||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
|
||||
enforce_impl_params_are_constrained(tcx, id.owner_id.def_id);
|
||||
if min_specialization {
|
||||
check_min_specialization(tcx, id.def_id.def_id);
|
||||
check_min_specialization(tcx, id.owner_id.def_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,7 +381,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
|
|||
error = true;
|
||||
}
|
||||
if let hir::IsAsync::Async = sig.header.asyncness {
|
||||
let span = tcx.def_span(it.def_id);
|
||||
let span = tcx.def_span(it.owner_id);
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
span,
|
||||
|
|
|
@ -29,7 +29,7 @@ pub(super) fn infer_predicates<'tcx>(
|
|||
|
||||
// Visit all the crates and infer predicates
|
||||
for id in tcx.hir().items() {
|
||||
let item_did = id.def_id;
|
||||
let item_did = id.owner_id;
|
||||
|
||||
debug!("InferVisitor::visit_item(item={:?})", item_did);
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ pub fn test_inferred_outlives(tcx: TyCtxt<'_>) {
|
|||
for id in tcx.hir().items() {
|
||||
// For unit testing: check for a special "rustc_outlives"
|
||||
// attribute and report an error with various results if found.
|
||||
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_outlives) {
|
||||
let inferred_outlives_of = tcx.inferred_outlives_of(id.def_id);
|
||||
if tcx.has_attr(id.owner_id.to_def_id(), sym::rustc_outlives) {
|
||||
let inferred_outlives_of = tcx.inferred_outlives_of(id.owner_id);
|
||||
struct_span_err!(
|
||||
tcx.sess,
|
||||
tcx.def_span(id.def_id),
|
||||
tcx.def_span(id.owner_id),
|
||||
E0640,
|
||||
"{:?}",
|
||||
inferred_outlives_of
|
||||
|
|
|
@ -6,9 +6,10 @@ pub fn test_variance(tcx: TyCtxt<'_>) {
|
|||
// For unit testing: check for a special "rustc_variance"
|
||||
// attribute and report an error with various results if found.
|
||||
for id in tcx.hir().items() {
|
||||
if tcx.has_attr(id.def_id.to_def_id(), sym::rustc_variance) {
|
||||
let variances_of = tcx.variances_of(id.def_id);
|
||||
struct_span_err!(tcx.sess, tcx.def_span(id.def_id), E0208, "{:?}", variances_of).emit();
|
||||
if tcx.has_attr(id.owner_id.to_def_id(), sym::rustc_variance) {
|
||||
let variances_of = tcx.variances_of(id.owner_id);
|
||||
struct_span_err!(tcx.sess, tcx.def_span(id.owner_id), E0208, "{:?}", variances_of)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue