diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-06 08:45:07 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-30 08:45:43 +0000 |
| commit | cb158c2119b44c3d2c61d8e2914d39aa02dfbb1f (patch) | |
| tree | f4e6f6b49778341ba8e16c4f6b677ddbf1932199 /compiler/rustc_hir_analysis | |
| parent | 632a921479783f474d16dea360a1b0a887ea02db (diff) | |
| download | rust-cb158c2119b44c3d2c61d8e2914d39aa02dfbb1f.tar.gz rust-cb158c2119b44c3d2c61d8e2914d39aa02dfbb1f.zip | |
Merge `lower_item` into `check_item_type`
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 88 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/collect.rs | 103 |
3 files changed, 77 insertions, 115 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index d21f9116236..b72e838a010 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -758,17 +758,34 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } match tcx.def_kind(def_id) { - DefKind::Static { .. } => { - check_static_inhabited(tcx, def_id); - check_static_linkage(tcx, def_id); - wfcheck::check_static_item(tcx, def_id)?; + def_kind @ (DefKind::Static { .. } | DefKind::Const) => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().predicates_of(def_id); + match def_kind { + DefKind::Static { .. } => { + check_static_inhabited(tcx, def_id); + check_static_linkage(tcx, def_id); + wfcheck::check_static_item(tcx, def_id)?; + } + DefKind::Const => {} + _ => unreachable!(), + } } - DefKind::Const => {} DefKind::Enum => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().predicates_of(def_id); + crate::collect::lower_enum_variant_types(tcx, def_id.to_def_id()); check_enum(tcx, def_id); check_variances_for_type_defn(tcx, def_id); } DefKind::Fn => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().fn_sig(def_id); + tcx.ensure_ok().codegen_fn_attrs(def_id); if let Some(i) = tcx.intrinsic(def_id) { intrinsic::check_intrinsic_type( tcx, @@ -779,6 +796,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } } DefKind::Impl { of_trait } => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().impl_trait_header(def_id); + tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().associated_items(def_id); if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) { tcx.ensure_ok() .coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id)?; @@ -787,6 +809,11 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } } DefKind::Trait => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().trait_def(def_id); + tcx.ensure_ok().explicit_super_predicates_of(def_id); + tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().associated_items(def_id); let assoc_items = tcx.associated_items(def_id); check_on_unimplemented(tcx, def_id); @@ -805,12 +832,32 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } } } - DefKind::Struct => { - check_struct(tcx, def_id); - check_variances_for_type_defn(tcx, def_id); + DefKind::TraitAlias => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().explicit_implied_predicates_of(def_id); + tcx.ensure_ok().explicit_super_predicates_of(def_id); + tcx.ensure_ok().predicates_of(def_id); } - DefKind::Union => { - check_union(tcx, def_id); + def_kind @ (DefKind::Struct | DefKind::Union) => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().predicates_of(def_id); + + let adt = tcx.adt_def(def_id).non_enum_variant(); + for f in adt.fields.iter() { + tcx.ensure_ok().generics_of(f.did); + tcx.ensure_ok().type_of(f.did); + tcx.ensure_ok().predicates_of(f.did); + } + + if let Some((_, ctor_def_id)) = adt.ctor { + crate::collect::lower_variant_ctor(tcx, ctor_def_id.expect_local()); + } + match def_kind { + DefKind::Struct => check_struct(tcx, def_id), + DefKind::Union => check_union(tcx, def_id), + _ => unreachable!(), + } check_variances_for_type_defn(tcx, def_id); } DefKind::OpaqueTy => { @@ -838,6 +885,9 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } } DefKind::TyAlias => { + tcx.ensure_ok().generics_of(def_id); + tcx.ensure_ok().type_of(def_id); + tcx.ensure_ok().predicates_of(def_id); check_type_alias_type_params_are_used(tcx, def_id); if tcx.type_alias_is_lazy(def_id) { res = res.and(enter_wf_checking_ctxt(tcx, def_id, |wfcx| { @@ -897,11 +947,23 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } let item = tcx.hir_foreign_item(item.id); - match &item.kind { - hir::ForeignItemKind::Fn(sig, _, _) => { + tcx.ensure_ok().generics_of(item.owner_id); + tcx.ensure_ok().type_of(item.owner_id); + tcx.ensure_ok().predicates_of(item.owner_id); + if tcx.is_conditionally_const(def_id) { + tcx.ensure_ok().explicit_implied_const_bounds(def_id); + tcx.ensure_ok().const_conditions(def_id); + } + match item.kind { + hir::ForeignItemKind::Fn(sig, ..) => { + tcx.ensure_ok().codegen_fn_attrs(item.owner_id); + tcx.ensure_ok().fn_sig(item.owner_id); require_c_abi_if_c_variadic(tcx, sig.decl, abi, item.span); } - _ => {} + hir::ForeignItemKind::Static(..) => { + tcx.ensure_ok().codegen_fn_attrs(item.owner_id); + } + _ => (), } } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 0cd4f8fbd01..792214355a9 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -230,7 +230,6 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() ?item.owner_id, item.name = ? tcx.def_path_str(def_id) ); - crate::collect::lower_item(tcx, item.item_id()); match item.kind { // Right now we check that every default trait implementation diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index d7568554669..f6d114ee290 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -615,105 +615,6 @@ fn get_new_lifetime_name<'tcx>( (1..).flat_map(a_to_z_repeat_n).find(|lt| !existing_lifetimes.contains(lt.as_str())).unwrap() } -#[instrument(level = "debug", skip_all)] -pub(super) fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { - let it = tcx.hir_item(item_id); - debug!(item = ?it.kind.ident(), id = %it.hir_id()); - let def_id = item_id.owner_id.def_id; - - match &it.kind { - // These don't define types. - hir::ItemKind::ExternCrate(..) - | hir::ItemKind::Use(..) - | hir::ItemKind::Macro(..) - | hir::ItemKind::Mod(..) - | hir::ItemKind::GlobalAsm { .. } => {} - hir::ItemKind::ForeignMod { items, .. } => { - for item in *items { - let item = tcx.hir_foreign_item(item.id); - tcx.ensure_ok().generics_of(item.owner_id); - tcx.ensure_ok().type_of(item.owner_id); - tcx.ensure_ok().predicates_of(item.owner_id); - if tcx.is_conditionally_const(def_id) { - tcx.ensure_ok().explicit_implied_const_bounds(def_id); - tcx.ensure_ok().const_conditions(def_id); - } - match item.kind { - hir::ForeignItemKind::Fn(..) => { - tcx.ensure_ok().codegen_fn_attrs(item.owner_id); - tcx.ensure_ok().fn_sig(item.owner_id) - } - hir::ForeignItemKind::Static(..) => { - tcx.ensure_ok().codegen_fn_attrs(item.owner_id); - } - _ => (), - } - } - } - hir::ItemKind::Enum(..) => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - lower_enum_variant_types(tcx, def_id.to_def_id()); - } - hir::ItemKind::Impl { .. } => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().impl_trait_header(def_id); - tcx.ensure_ok().predicates_of(def_id); - tcx.ensure_ok().associated_items(def_id); - } - hir::ItemKind::Trait(..) => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().trait_def(def_id); - tcx.at(it.span).explicit_super_predicates_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - tcx.ensure_ok().associated_items(def_id); - } - hir::ItemKind::TraitAlias(..) => { - tcx.ensure_ok().generics_of(def_id); - tcx.at(it.span).explicit_implied_predicates_of(def_id); - tcx.at(it.span).explicit_super_predicates_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - } - hir::ItemKind::Struct(_, _, struct_def) | hir::ItemKind::Union(_, _, struct_def) => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - - for f in struct_def.fields() { - tcx.ensure_ok().generics_of(f.def_id); - tcx.ensure_ok().type_of(f.def_id); - tcx.ensure_ok().predicates_of(f.def_id); - } - - if let Some(ctor_def_id) = struct_def.ctor_def_id() { - lower_variant_ctor(tcx, ctor_def_id); - } - } - - hir::ItemKind::TyAlias(..) => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - } - - hir::ItemKind::Static(..) | hir::ItemKind::Const(..) => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - } - - hir::ItemKind::Fn { .. } => { - tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); - tcx.ensure_ok().fn_sig(def_id); - tcx.ensure_ok().codegen_fn_attrs(def_id); - } - } -} - pub(crate) fn lower_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.owner_id; @@ -761,13 +662,13 @@ pub(super) fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) { } } -fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { +pub(super) fn lower_variant_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); } -fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { +pub(super) fn lower_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId) { let def = tcx.adt_def(def_id); let repr_type = def.repr().discr_type(); let initial = repr_type.initial_discriminant(tcx); |
