Skip to content

Commit 38ef94a

Browse files
committed
Stop requiring HIR for trait item wf checks
1 parent 6166cd6 commit 38ef94a

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ 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_variances_for_type_defn, check_where_clauses, enter_wf_checking_ctxt,
40+
check_trait_item, check_variances_for_type_defn, check_where_clauses, enter_wf_checking_ctxt,
4141
};
4242

4343
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<(),
981981
tcx.ensure_ok().type_of(def_id);
982982
tcx.ensure_ok().fn_sig(def_id);
983983
tcx.ensure_ok().predicates_of(def_id);
984+
let assoc_item = tcx.associated_item(def_id);
985+
match assoc_item.container {
986+
ty::AssocItemContainer::Impl => {}
987+
ty::AssocItemContainer::Trait => {
988+
res = res.and(check_trait_item(tcx, def_id));
989+
}
990+
}
984991
}
985992
DefKind::AssocConst => {
986993
tcx.ensure_ok().type_of(def_id);
987994
tcx.ensure_ok().predicates_of(def_id);
995+
let assoc_item = tcx.associated_item(def_id);
996+
match assoc_item.container {
997+
ty::AssocItemContainer::Impl => {}
998+
ty::AssocItemContainer::Trait => {
999+
res = res.and(check_trait_item(tcx, def_id));
1000+
}
1001+
}
9881002
}
9891003
DefKind::AssocTy => {
9901004
tcx.ensure_ok().predicates_of(def_id);
@@ -995,6 +1009,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
9951009
ty::AssocItemContainer::Trait => {
9961010
tcx.ensure_ok().item_bounds(def_id);
9971011
tcx.ensure_ok().item_self_bounds(def_id);
1012+
res = res.and(check_trait_item(tcx, def_id));
9981013
assoc_item.defaultness(tcx).has_value()
9991014
}
10001015
};

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGua
195195
res = res.and(match node {
196196
hir::Node::Crate(_) => bug!("check_well_formed cannot be applied to the crate root"),
197197
hir::Node::Item(item) => check_item(tcx, item),
198-
hir::Node::TraitItem(item) => check_trait_item(tcx, item),
198+
hir::Node::TraitItem(..) => Ok(()),
199199
hir::Node::ImplItem(item) => check_impl_item(tcx, item),
200200
hir::Node::ForeignItem(item) => check_foreign_item(tcx, item),
201201
hir::Node::ConstBlock(_) | hir::Node::Expr(_) | hir::Node::OpaqueTy(_) => Ok(()),
@@ -322,18 +322,16 @@ fn check_foreign_item<'tcx>(
322322
}
323323
}
324324

325-
fn check_trait_item<'tcx>(
325+
pub(crate) fn check_trait_item<'tcx>(
326326
tcx: TyCtxt<'tcx>,
327-
trait_item: &'tcx hir::TraitItem<'tcx>,
327+
def_id: LocalDefId,
328328
) -> Result<(), ErrorGuaranteed> {
329-
let def_id = trait_item.owner_id.def_id;
330-
331329
// Check that an item definition in a subtrait is shadowing a supertrait item.
332330
lint_item_shadowing_supertrait_item(tcx, def_id);
333331

334332
let mut res = check_associated_item(tcx, def_id);
335333

336-
if matches!(trait_item.kind, hir::TraitItemKind::Fn(..)) {
334+
if matches!(tcx.def_kind(def_id), DefKind::AssocFn) {
337335
for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
338336
res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local()));
339337
}

tests/incremental/cyclic-trait-hierarchy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
pub trait T2 {}
77
#[cfg(cfail2)]
88
pub trait T2: T1 {}
9-
//[cfail2]~^ ERROR cycle detected when computing the implied predicates of `T2`
9+
//[cfail2]~^ ERROR cycle detected when computing the super predicates of `T2`
1010

1111
pub trait T1: T2 {}
1212

0 commit comments

Comments
 (0)