diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-13 09:39:04 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-30 08:45:43 +0000 |
| commit | 38ef94aef13d149728b05c7a6fa523a4ea85399e (patch) | |
| tree | e83a0e26ba0e171da0fdcf56f57dc40fc5077e01 | |
| parent | 6166cd6b50b9c513ae8f2da45a7f399fd4fcab29 (diff) | |
| download | rust-38ef94aef13d149728b05c7a6fa523a4ea85399e.tar.gz rust-38ef94aef13d149728b05c7a6fa523a4ea85399e.zip | |
Stop requiring HIR for trait item wf checks
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 10 | ||||
| -rw-r--r-- | tests/incremental/cyclic-trait-hierarchy.rs | 2 |
3 files changed, 21 insertions, 8 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index e3f9ca64c58..7732809a41d 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -37,7 +37,7 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir}; use super::compare_impl_item::check_type_bounds; use super::*; use crate::check::wfcheck::{ - check_variances_for_type_defn, check_where_clauses, enter_wf_checking_ctxt, + check_trait_item, check_variances_for_type_defn, check_where_clauses, enter_wf_checking_ctxt, }; fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) { @@ -981,10 +981,24 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().fn_sig(def_id); tcx.ensure_ok().predicates_of(def_id); + let assoc_item = tcx.associated_item(def_id); + match assoc_item.container { + ty::AssocItemContainer::Impl => {} + ty::AssocItemContainer::Trait => { + res = res.and(check_trait_item(tcx, def_id)); + } + } } DefKind::AssocConst => { tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().predicates_of(def_id); + let assoc_item = tcx.associated_item(def_id); + match assoc_item.container { + ty::AssocItemContainer::Impl => {} + ty::AssocItemContainer::Trait => { + res = res.and(check_trait_item(tcx, def_id)); + } + } } DefKind::AssocTy => { tcx.ensure_ok().predicates_of(def_id); @@ -995,6 +1009,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ty::AssocItemContainer::Trait => { tcx.ensure_ok().item_bounds(def_id); tcx.ensure_ok().item_self_bounds(def_id); + res = res.and(check_trait_item(tcx, def_id)); assoc_item.defaultness(tcx).has_value() } }; diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 3404070a82d..597566f6158 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -195,7 +195,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua res = res.and(match node { hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"), hir::Node::Item(item) => check_item(tcx, item), - hir::Node::TraitItem(item) => check_trait_item(tcx, item), + hir::Node::TraitItem(..) => Ok(()), hir::Node::ImplItem(item) => check_impl_item(tcx, item), hir::Node::ForeignItem(item) => check_foreign_item(tcx, item), hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => Ok(()), @@ -322,18 +322,16 @@ fn check_foreign_item<'tcx>( } } -fn check_trait_item<'tcx>( +pub(crate) fn check_trait_item<'tcx>( tcx: TyCtxt<'tcx>, - trait_item: &'tcx hir::TraitItem<'tcx>, + def_id: LocalDefId, ) -> Result<(), ErrorGuaranteed> { - let def_id = trait_item.owner_id.def_id; - // Check that an item definition in a subtrait is shadowing a supertrait item. lint_item_shadowing_supertrait_item(tcx, def_id); let mut res = check_associated_item(tcx, def_id); - if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) { + if matches!(tcx.def_kind(def_id), DefKind::AssocFn) { for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) { res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local())); } diff --git a/tests/incremental/cyclic-trait-hierarchy.rs b/tests/incremental/cyclic-trait-hierarchy.rs index 7a3293303a9..6a6aedee832 100644 --- a/tests/incremental/cyclic-trait-hierarchy.rs +++ b/tests/incremental/cyclic-trait-hierarchy.rs @@ -6,7 +6,7 @@ pub trait T2 {} #[cfg(cfail2)] pub trait T2: T1 {} -//[cfail2]~^ ERROR cycle detected when computing the implied predicates of `T2` +//[cfail2]~^ ERROR cycle detected when computing the super predicates of `T2` pub trait T1: T2 {} |
