Make predicate filter in probe_ty_param_bounds_in_generics more explicit

This commit is contained in:
Michael Goulet 2024-10-26 19:01:27 +00:00
parent 75eff9a574
commit ac67d295b9

View File

@ -606,12 +606,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
let mut bounds = Bounds::default(); let mut bounds = Bounds::default();
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter); icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics( let where_bounds_that_match =
generics, icx.probe_ty_param_bounds_in_generics(generics, item.owner_id.def_id, filter);
item.owner_id.def_id,
self_param_ty,
filter,
);
// Combine the two lists to form the complete set of superbounds: // Combine the two lists to form the complete set of superbounds:
let implied_bounds = let implied_bounds =
@ -768,7 +764,6 @@ pub(super) fn type_param_predicates<'tcx>(
} }
use rustc_hir::*; use rustc_hir::*;
use rustc_middle::ty::Ty;
// In the HIR, bounds can derive from two places. Either // In the HIR, bounds can derive from two places. Either
// written inline like `<T: Foo>` or in a where-clause like // written inline like `<T: Foo>` or in a where-clause like
@ -778,7 +773,6 @@ pub(super) fn type_param_predicates<'tcx>(
let param_owner = tcx.hir().ty_param_owner(def_id); let param_owner = tcx.hir().ty_param_owner(def_id);
let generics = tcx.generics_of(param_owner); let generics = tcx.generics_of(param_owner);
let index = generics.param_def_id_to_index[&def_id.to_def_id()]; let index = generics.param_def_id_to_index[&def_id.to_def_id()];
let ty = Ty::new_param(tcx, index, tcx.hir().ty_param_name(def_id));
// Don't look for bounds where the type parameter isn't in scope. // Don't look for bounds where the type parameter isn't in scope.
let parent = if item_def_id == param_owner { let parent = if item_def_id == param_owner {
@ -815,7 +809,6 @@ pub(super) fn type_param_predicates<'tcx>(
icx.probe_ty_param_bounds_in_generics( icx.probe_ty_param_bounds_in_generics(
hir_generics, hir_generics,
def_id, def_id,
ty,
PredicateFilter::SelfThatDefines(assoc_name), PredicateFilter::SelfThatDefines(assoc_name),
) )
.into_iter() .into_iter()
@ -841,7 +834,6 @@ fn probe_ty_param_bounds_in_generics(
&self, &self,
hir_generics: &'tcx hir::Generics<'tcx>, hir_generics: &'tcx hir::Generics<'tcx>,
param_def_id: LocalDefId, param_def_id: LocalDefId,
ty: Ty<'tcx>,
filter: PredicateFilter, filter: PredicateFilter,
) -> Vec<(ty::Clause<'tcx>, Span)> { ) -> Vec<(ty::Clause<'tcx>, Span)> {
let mut bounds = Bounds::default(); let mut bounds = Bounds::default();
@ -851,13 +843,21 @@ fn probe_ty_param_bounds_in_generics(
continue; continue;
}; };
let bound_ty = if predicate.is_param_bound(param_def_id.to_def_id()) { match filter {
ty _ if predicate.is_param_bound(param_def_id.to_def_id()) => {
} else if matches!(filter, PredicateFilter::All) { // Ok
self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty) }
} else { PredicateFilter::All => {
continue; // Ok
}; }
PredicateFilter::SelfOnly
| PredicateFilter::SelfThatDefines(_)
| PredicateFilter::SelfConstIfConst
| PredicateFilter::SelfAndAssociatedTypeBounds => continue,
PredicateFilter::ConstIfConst => unreachable!(),
}
let bound_ty = self.lowerer().lower_ty_maybe_return_type_notation(predicate.bounded_ty);
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id); let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
self.lowerer().lower_bounds( self.lowerer().lower_bounds(