Skip to content

Commit 06cc8b9

Browse files
committed
Perform trait checks in the type based wf checker
1 parent 695e297 commit 06cc8b9

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,19 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
843843
_ => {}
844844
}
845845
}
846+
res = res.and(wfcheck::check_trait(tcx, def_id));
847+
wfcheck::check_gat_where_clauses(tcx, def_id);
848+
// Trait aliases do not have hir checks anymore
849+
return res;
846850
}
847851
DefKind::TraitAlias => {
848852
tcx.ensure_ok().generics_of(def_id);
849853
tcx.ensure_ok().explicit_implied_predicates_of(def_id);
850854
tcx.ensure_ok().explicit_super_predicates_of(def_id);
851855
tcx.ensure_ok().predicates_of(def_id);
856+
res = res.and(wfcheck::check_trait(tcx, def_id));
857+
// Trait aliases do not have hir checks anymore
858+
return res;
852859
}
853860
def_kind @ (DefKind::Struct | DefKind::Union) => {
854861
tcx.ensure_ok().generics_of(def_id);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,6 @@ pub(super) fn check_item<'tcx>(
293293
hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false),
294294
hir::ItemKind::Union(..) => check_type_defn(tcx, item, true),
295295
hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true),
296-
hir::ItemKind::Trait(..) => check_trait(tcx, item),
297-
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
298296
_ => Ok(()),
299297
}
300298
}
@@ -345,7 +343,7 @@ pub(crate) fn check_trait_item<'tcx>(
345343
/// fn into_iter<'a>(&'a self) -> Self::Iter<'a>;
346344
/// }
347345
/// ```
348-
fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
346+
pub(crate) fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
349347
// Associates every GAT's def_id to a list of possibly missing bounds detected by this lint.
350348
let mut required_bounds_by_item = FxIndexMap::default();
351349
let associated_items = tcx.associated_items(trait_def_id);
@@ -1106,11 +1104,8 @@ fn check_type_defn<'tcx>(
11061104
})
11071105
}
11081106

1109-
#[instrument(skip(tcx, item))]
1110-
fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuaranteed> {
1111-
debug!(?item.owner_id);
1112-
1113-
let def_id = item.owner_id.def_id;
1107+
#[instrument(skip(tcx))]
1108+
pub(crate) fn check_trait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
11141109
if tcx.is_lang_item(def_id.into(), LangItem::PointeeSized) {
11151110
// `PointeeSized` is removed during lowering.
11161111
return Ok(());
@@ -1136,10 +1131,6 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant
11361131
Ok(())
11371132
});
11381133

1139-
// Only check traits, don't check trait aliases
1140-
if let hir::ItemKind::Trait(..) = item.kind {
1141-
check_gat_where_clauses(tcx, item.owner_id.def_id);
1142-
}
11431134
res
11441135
}
11451136

0 commit comments

Comments
 (0)