Stop requiring HIR for trait item wf checks
This commit is contained in:
parent
6166cd6b50
commit
38ef94aef1
3 changed files with 21 additions and 8 deletions
|
|
@ -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()
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue