Skip to content

Commit 5ddae35

Browse files
committed
Stop requiring HIR for impl item wf checks
1 parent 38ef94a commit 5ddae35

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
3737
use super::compare_impl_item::check_type_bounds;
3838
use super::*;
3939
use crate::check::wfcheck::{
40-
check_trait_item, check_variances_for_type_defn, check_where_clauses, enter_wf_checking_ctxt,
40+
check_associated_item, check_trait_item, check_variances_for_type_defn, check_where_clauses,
41+
enter_wf_checking_ctxt,
4142
};
4243

4344
fn add_abi_diag_help<T: EmissionGuarantee>(abi: ExternAbi, diag: &mut Diag<'_, T>) {
@@ -981,6 +982,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
981982
tcx.ensure_ok().type_of(def_id);
982983
tcx.ensure_ok().fn_sig(def_id);
983984
tcx.ensure_ok().predicates_of(def_id);
985+
res = res.and(check_associated_item(tcx, def_id));
984986
let assoc_item = tcx.associated_item(def_id);
985987
match assoc_item.container {
986988
ty::AssocItemContainer::Impl => {}
@@ -992,6 +994,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
992994
DefKind::AssocConst => {
993995
tcx.ensure_ok().type_of(def_id);
994996
tcx.ensure_ok().predicates_of(def_id);
997+
res = res.and(check_associated_item(tcx, def_id));
995998
let assoc_item = tcx.associated_item(def_id);
996999
match assoc_item.container {
9971000
ty::AssocItemContainer::Impl => {}
@@ -1002,6 +1005,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
10021005
}
10031006
DefKind::AssocTy => {
10041007
tcx.ensure_ok().predicates_of(def_id);
1008+
res = res.and(check_associated_item(tcx, def_id));
10051009

10061010
let assoc_item = tcx.associated_item(def_id);
10071011
let has_type = match assoc_item.container {

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
196196
hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
197197
hir::Node::Item(item) => check_item(tcx, item),
198198
hir::Node::TraitItem(..) => Ok(()),
199-
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
199+
hir::Node::ImplItem(..) => Ok(()),
200200
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
201201
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => Ok(()),
202202
_ => unreachable!("{node:?}"),
@@ -329,7 +329,7 @@ pub(crate) fn check_trait_item<'tcx>(
329329
// Check that an item definition in a subtrait is shadowing a supertrait item.
330330
lint_item_shadowing_supertrait_item(tcx, def_id);
331331

332-
let mut res = check_associated_item(tcx, def_id);
332+
let mut res = Ok(());
333333

334334
if matches!(tcx.def_kind(def_id), DefKind::AssocFn) {
335335
for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
@@ -812,13 +812,6 @@ fn lint_item_shadowing_supertrait_item<'tcx>(tcx: TyCtxt<'tcx>, trait_item_def_i
812812
}
813813
}
814814

815-
fn check_impl_item<'tcx>(
816-
tcx: TyCtxt<'tcx>,
817-
impl_item: &'tcx hir::ImplItem<'tcx>,
818-
) -> Result<(), ErrorGuaranteed> {
819-
check_associated_item(tcx, impl_item.owner_id.def_id)
820-
}
821-
822815
fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), ErrorGuaranteed> {
823816
match param.kind {
824817
// We currently only check wf of const params here.
@@ -945,7 +938,10 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &ty::GenericParamDef) -> Result<(), Er
945938
}
946939

947940
#[instrument(level = "debug", skip(tcx))]
948-
fn check_associated_item(tcx: TyCtxt<'_>, item_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
941+
pub(crate) fn check_associated_item(
942+
tcx: TyCtxt<'_>,
943+
item_id: LocalDefId,
944+
) -> Result<(), ErrorGuaranteed> {
949945
let loc = Some(WellFormedLoc::Ty(item_id));
950946
enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
951947
let item = tcx.associated_item(item_id);

0 commit comments

Comments
 (0)