1
Fork 0

RPITITs are considered object-safe, they're always on Self:Sized methods

This commit is contained in:
Michael Goulet 2023-09-02 04:33:58 +00:00
parent 361f8ba847
commit 7a6b52bf0d
6 changed files with 38 additions and 18 deletions

View file

@ -354,6 +354,12 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
// FIXME(associated_const_equality): Also add associated consts to
// the requirements here.
if item.kind == ty::AssocKind::Type {
// RPITITs are not checked here, since they are not (currently) object-safe
// and cannot be named from a non-`Self: Sized` method.
if item.is_impl_trait_in_trait() {
continue;
}
requirements
.extend(tcx.item_bounds(item.def_id).iter_instantiated(tcx, trait_ref.args));
}

View file

@ -535,6 +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())
.filter_map(
|item| if item.kind == ty::AssocKind::Type { Some(item.def_id) } else { None },
)