1
Fork 0

Ignore Self in bounds check for associated types with Self:Sized

This commit is contained in:
Michael Goulet 2025-02-15 20:38:08 +00:00
parent 608e228ca9
commit 309e371f7b
2 changed files with 17 additions and 0 deletions

View file

@ -187,7 +187,10 @@ fn predicates_reference_self(
fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> {
tcx.associated_items(trait_def_id)
.in_definition_order()
// We're only looking at associated type bounds
.filter(|item| item.kind == ty::AssocKind::Type)
// Ignore GATs with `Self: Sized`
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
.flat_map(|item| tcx.explicit_item_bounds(item.def_id).iter_identity_copied())
.filter_map(|(clause, sp)| {
// Item bounds *can* have self projections, since they never get

View file

@ -0,0 +1,14 @@
// Ensure that we properly ignore the `B<Self>` associated type bound on `A::T`
// since that associated type requires `Self: Sized`.
//@ check-pass
struct X(&'static dyn A);
trait A {
type T: B<Self> where Self: Sized;
}
trait B<T> {}
fn main() {}