Skip to content

Commit 63482af

Browse files
authored
Rollup merge of rust-lang#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`.
2 parents 376a6f9 + 34e0878 commit 63482af

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
774774
// instantiation that replaces `Self` with the object type itself. Hence,
775775
// a `&self` method will wind up with an argument type like `&dyn Trait`.
776776
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+
);
783790
}
784791

785792
#[instrument(level = "debug", skip(self))]
786793
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-
789794
let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
790795
let bound_predicate = predicate.kind();
791796
match bound_predicate.skip_binder() {
@@ -806,7 +811,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
806811
}
807812
});
808813

809-
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
814+
self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
810815
this.push_candidate(
811816
Candidate {
812817
item,
@@ -820,15 +825,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
820825

821826
// Do a search through a list of bounds, using a callback to actually
822827
// create the candidates.
823-
fn elaborate_bounds<F>(
828+
fn assemble_candidates_for_bounds<F>(
824829
&mut self,
825830
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
826831
mut mk_cand: F,
827832
) where
828833
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
829834
{
830-
let tcx = self.tcx;
831-
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
835+
for bound_trait_ref in bounds {
832836
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
833837
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
834838
if !self.has_applicable_self(&item) {

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub use self::specialize::{
6262
};
6363
pub use self::structural_normalize::StructurallyNormalizeExt;
6464
pub use self::util::{
65-
elaborate, expand_trait_aliases, impl_item_is_final, supertraits, transitive_bounds,
65+
elaborate, expand_trait_aliases, impl_item_is_final, supertraits,
6666
transitive_bounds_that_define_assoc_item, upcast_choices, with_replaced_escaping_bound_vars,
6767
BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo,
6868
};

compiler/rustc_type_ir/src/elaborate.rs

-9
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ pub fn supertraits<I: Interner>(
264264
elaborate(cx, [trait_ref.upcast(cx)]).filter_only_self().filter_to_traits()
265265
}
266266

267-
pub fn transitive_bounds<I: Interner>(
268-
cx: I,
269-
trait_refs: impl Iterator<Item = ty::Binder<I, ty::TraitRef<I>>>,
270-
) -> FilterToTraits<I, Elaborator<I, I::Clause>> {
271-
elaborate(cx, trait_refs.map(|trait_ref| trait_ref.upcast(cx)))
272-
.filter_only_self()
273-
.filter_to_traits()
274-
}
275-
276267
impl<I: Interner> Elaborator<I, I::Clause> {
277268
fn filter_to_traits(self) -> FilterToTraits<I, Self> {
278269
FilterToTraits { _cx: PhantomData, base_iterator: self }

0 commit comments

Comments
 (0)