Split item bounds and item super predicates

This commit is contained in:
Michael Goulet 2024-03-20 12:52:48 -04:00
parent a128516cf9
commit aa39dbb962
20 changed files with 186 additions and 46 deletions

View file

@ -1098,8 +1098,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
))
}
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
self.tcx.item_bounds(def_id).instantiate(self.tcx, args).iter().find_map(
|pred| {
self.tcx
.item_super_predicates(def_id)
.instantiate(self.tcx, args)
.iter()
.find_map(|pred| {
if let ty::ClauseKind::Projection(proj) = pred.kind().skip_binder()
&& Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output()
// args tuple will always be args[1]
@ -1113,8 +1116,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} else {
None
}
},
)
})
}
ty::Dynamic(data, _, ty::Dyn) => {
data.iter().find_map(|pred| {

View file

@ -1617,21 +1617,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
_ => return ControlFlow::Continue(()),
};
for bound in
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
{
// HACK: On subsequent recursions, we only care about bounds that don't
// share the same type as `self_ty`. This is because for truly rigid
// projections, we will never be able to equate, e.g. `<T as Tr>::A`
// with `<<T as Tr>::A as Tr>::A`.
if in_parent_alias_type {
match bound.kind().skip_binder() {
ty::ClauseKind::Trait(tr) if tr.self_ty() == self_ty => continue,
ty::ClauseKind::Projection(p) if p.self_ty() == self_ty => continue,
_ => {}
}
}
// HACK: On subsequent recursions, we only care about bounds that don't
// share the same type as `self_ty`. This is because for truly rigid
// projections, we will never be able to equate, e.g. `<T as Tr>::A`
// with `<<T as Tr>::A as Tr>::A`.
let relevant_bounds = if in_parent_alias_type {
self.tcx().item_non_self_assumptions(alias_ty.def_id)
} else {
self.tcx().item_super_predicates(alias_ty.def_id)
};
for bound in relevant_bounds.instantiate(self.tcx(), alias_ty.args) {
for_each(self, bound, idx)?;
idx += 1;
}