Rollup merge of #128559 - compiler-errors:elaborate, r=lcnr
Don't re-elaborated already elaborated caller bounds in method probe Caller bounds are already elaborated. Only elaborate object candidates' principals. Also removes the only usage of `transitive_bounds`.
This commit is contained in:
commit
63482af982
@ -774,18 +774,23 @@ fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
|
|||||||
// instantiation that replaces `Self` with the object type itself. Hence,
|
// instantiation that replaces `Self` with the object type itself. Hence,
|
||||||
// a `&self` method will wind up with an argument type like `&dyn Trait`.
|
// a `&self` method will wind up with an argument type like `&dyn Trait`.
|
||||||
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
|
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
|
||||||
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
|
self.assemble_candidates_for_bounds(
|
||||||
this.push_candidate(
|
traits::supertraits(self.tcx, trait_ref),
|
||||||
Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: smallvec![] },
|
|this, new_trait_ref, item| {
|
||||||
true,
|
this.push_candidate(
|
||||||
);
|
Candidate {
|
||||||
});
|
item,
|
||||||
|
kind: ObjectCandidate(new_trait_ref),
|
||||||
|
import_ids: smallvec![],
|
||||||
|
},
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip(self))]
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
||||||
// FIXME: do we want to commit to this behavior for param bounds?
|
|
||||||
|
|
||||||
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
|
||||||
let bound_predicate = predicate.kind();
|
let bound_predicate = predicate.kind();
|
||||||
match bound_predicate.skip_binder() {
|
match bound_predicate.skip_binder() {
|
||||||
@ -806,7 +811,7 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
|
self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
|
||||||
this.push_candidate(
|
this.push_candidate(
|
||||||
Candidate {
|
Candidate {
|
||||||
item,
|
item,
|
||||||
@ -820,15 +825,14 @@ fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) {
|
|||||||
|
|
||||||
// Do a search through a list of bounds, using a callback to actually
|
// Do a search through a list of bounds, using a callback to actually
|
||||||
// create the candidates.
|
// create the candidates.
|
||||||
fn elaborate_bounds<F>(
|
fn assemble_candidates_for_bounds<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
|
||||||
mut mk_cand: F,
|
mut mk_cand: F,
|
||||||
) where
|
) where
|
||||||
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
|
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
|
||||||
{
|
{
|
||||||
let tcx = self.tcx;
|
for bound_trait_ref in bounds {
|
||||||
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
|
|
||||||
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
|
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
|
||||||
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
|
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
|
||||||
if !self.has_applicable_self(&item) {
|
if !self.has_applicable_self(&item) {
|
||||||
|
@ -62,7 +62,7 @@
|
|||||||
};
|
};
|
||||||
pub use self::structural_normalize::StructurallyNormalizeExt;
|
pub use self::structural_normalize::StructurallyNormalizeExt;
|
||||||
pub use self::util::{
|
pub use self::util::{
|
||||||
elaborate, expand_trait_aliases, impl_item_is_final, supertraits, transitive_bounds,
|
elaborate, expand_trait_aliases, impl_item_is_final, supertraits,
|
||||||
transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars,
|
transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars,
|
||||||
BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo,
|
BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo,
|
||||||
};
|
};
|
||||||
|
@ -264,15 +264,6 @@ pub fn supertraits<I: Interner>(
|
|||||||
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
|
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn transitive_bounds<I: Interner>(
|
|
||||||
cx: I,
|
|
||||||
trait_refs: impl Iterator<Item = ty::Binder<I, ty::TraitRef<I>>>,
|
|
||||||
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
|
|
||||||
elaborate(cx, trait_refs.map(|trait_ref| trait_ref.upcast(cx)))
|
|
||||||
.filter_only_self()
|
|
||||||
.filter_to_traits()
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<I: Interner> Elaborator<I, I::Clause> {
|
impl<I: Interner> Elaborator<I, I::Clause> {
|
||||||
fn filter_to_traits(self) -> FilterToTraits<I, Self> {
|
fn filter_to_traits(self) -> FilterToTraits<I, Self> {
|
||||||
FilterToTraits { _cx: PhantomData, base_iterator: self }
|
FilterToTraits { _cx: PhantomData, base_iterator: self }
|
||||||
|
Loading…
Reference in New Issue
Block a user