Do not require associated types with Self: Sized to uphold bounds when confirming object candidate

This commit is contained in:
Michael Goulet
2023-09-02 05:06:21 +00:00
parent 7a6b52bf0d
commit 07fc644132
7 changed files with 54 additions and 28 deletions

View File

@@ -535,9 +535,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let assoc_types: Vec<_> = tcx
.associated_items(trait_predicate.def_id())
.in_definition_order()
// RPITITs are not checked here, since they are not (currently) object-safe
// and cannot be named from a non-`Self: Sized` method.
.filter(|item| !item.is_impl_trait_in_trait())
// Associated types that require `Self: Sized` do not show up in the built-in
// implementation of `Trait for dyn Trait`, and can be dropped here.
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
.filter_map(
|item| if item.kind == ty::AssocKind::Type { Some(item.def_id) } else { None },
)