@@ -774,18 +774,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
774
774
// instantiation that replaces `Self` with the object type itself. Hence,
775
775
// a `&self` method will wind up with an argument type like `&dyn Trait`.
776
776
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
777
- self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
778
- this.push_candidate(
779
- Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: smallvec![] },
780
- true,
781
- );
782
- });
777
+ self.assemble_candidates_for_bounds(
778
+ traits::supertraits(self.tcx, trait_ref),
779
+ |this, new_trait_ref, item| {
780
+ this.push_candidate(
781
+ Candidate {
782
+ item,
783
+ kind: ObjectCandidate(new_trait_ref),
784
+ import_ids: smallvec![],
785
+ },
786
+ true,
787
+ );
788
+ },
789
+ );
783
790
}
784
791
785
792
#[instrument(level = "debug", skip(self))]
786
793
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
787
- // FIXME: do we want to commit to this behavior for param bounds?
788
-
789
794
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
790
795
let bound_predicate = predicate.kind();
791
796
match bound_predicate.skip_binder() {
@@ -806,7 +811,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
806
811
}
807
812
});
808
813
809
- self.elaborate_bounds (bounds, |this, poly_trait_ref, item| {
814
+ self.assemble_candidates_for_bounds (bounds, |this, poly_trait_ref, item| {
810
815
this.push_candidate(
811
816
Candidate {
812
817
item,
@@ -820,15 +825,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
820
825
821
826
// Do a search through a list of bounds, using a callback to actually
822
827
// create the candidates.
823
- fn elaborate_bounds <F>(
828
+ fn assemble_candidates_for_bounds <F>(
824
829
&mut self,
825
830
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
826
831
mut mk_cand: F,
827
832
) where
828
833
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
829
834
{
830
- let tcx = self.tcx;
831
- for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
835
+ for bound_trait_ref in bounds {
832
836
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
833
837
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
834
838
if !self.has_applicable_self(&item) {
0 commit comments