Skip to content

Commit

Permalink
Unrolled build for rust-lang#128559
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
rust-timer authored Aug 5, 2024
2 parents 2b78d92 + 34e0878 commit 0e4bb2c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
28 changes: 16 additions & 12 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,18 +774,23 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// instantiation that replaces `Self` with the object type itself. Hence,
// a `&self` method will wind up with an argument type like `&dyn Trait`.
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
this.push_candidate(
Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: smallvec![] },
true,
);
});
self.assemble_candidates_for_bounds(
traits::supertraits(self.tcx, trait_ref),
|this, new_trait_ref, item| {
this.push_candidate(
Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: smallvec![],
},
true,
);
},
);
}

#[instrument(level = "debug", skip(self))]
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 bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {
Expand All @@ -806,7 +811,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
});

self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
this.push_candidate(
Candidate {
item,
Expand All @@ -820,15 +825,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

// Do a search through a list of bounds, using a callback to actually
// create the candidates.
fn elaborate_bounds<F>(
fn assemble_candidates_for_bounds<F>(
&mut self,
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
mut mk_cand: F,
) where
F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
{
let tcx = self.tcx;
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
for bound_trait_ref in bounds {
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
if !self.has_applicable_self(&item) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub use self::specialize::{
};
pub use self::structural_normalize::StructurallyNormalizeExt;
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,
BoundVarReplacer, PlaceholderReplacer, TraitAliasExpander, TraitAliasExpansionInfo,
};
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_type_ir/src/elaborate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,6 @@ pub fn supertraits<I: Interner>(
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> {
fn filter_to_traits(self) -> FilterToTraits<I, Self> {
FilterToTraits { _cx: PhantomData, base_iterator: self }
Expand Down

0 comments on commit 0e4bb2c

Please sign in to comment.