Skip to content

Commit

Permalink
Rollup merge of rust-lang#55473 - ljedrz:transitive/elaborate_bounds_…
Browse files Browse the repository at this point in the history
…impl_iterator, r=estebank

Take advantage of impl Iterator in (transitive/elaborate)_bounds

Other than for `debug!`ging purposes, `bounds` are only iterated over, so they don't need to be collected into vectors.
  • Loading branch information
kennytm authored Oct 30, 2018
2 parents dc04aaf + 40079ac commit 0cf957d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/librustc/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ pub fn elaborate_trait_ref<'cx, 'gcx, 'tcx>(

pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>(
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
trait_refs: &[ty::PolyTraitRef<'tcx>])
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
-> Elaborator<'cx, 'gcx, 'tcx>
{
let predicates = trait_refs.iter()
.map(|trait_ref| trait_ref.to_predicate())
let predicates = trait_refs.map(|trait_ref| trait_ref.to_predicate())
.collect();
elaborate_predicates(tcx, predicates)
}
Expand Down Expand Up @@ -271,7 +270,7 @@ pub fn supertraits<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
}

pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
bounds: &[ty::PolyTraitRef<'tcx>])
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
-> Supertraits<'cx, 'gcx, 'tcx>
{
elaborate_trait_refs(tcx, bounds).filter_to_traits()
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,12 +1112,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
{
let tcx = self.tcx();

let bounds: Vec<_> = self.get_type_parameter_bounds(span, ty_param_def_id)
.predicates.into_iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()).collect();
let bounds = self.get_type_parameter_bounds(span, ty_param_def_id)
.predicates.into_iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref());

// Check that there is exactly one way to find an associated type with the
// correct name.
let suitable_bounds = traits::transitive_bounds(tcx, &bounds)
let suitable_bounds = traits::transitive_bounds(tcx, bounds)
.filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name));

let param_node_id = tcx.hir.as_local_node_id(ty_param_def_id).unwrap();
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use rustc::middle::stability;
use syntax::ast;
use syntax::util::lev_distance::{lev_distance, find_best_match_for_name};
use syntax_pos::{Span, symbol::Symbol};
use std::iter;
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
Expand Down Expand Up @@ -627,7 +628,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
// itself. Hence, a `&self` method will wind up with an
// argument type like `&Trait`.
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.elaborate_bounds(&[trait_ref], |this, new_trait_ref, item| {
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
let new_trait_ref = this.erase_late_bound_regions(&new_trait_ref);

let (xform_self_ty, xform_ret_ty) =
Expand All @@ -645,7 +646,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
param_ty: ty::ParamTy) {
// FIXME -- Do we want to commit to this behavior for param bounds?

let bounds: Vec<_> = self.param_env
let bounds = self.param_env
.caller_bounds
.iter()
.filter_map(|predicate| {
Expand All @@ -667,10 +668,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
ty::Predicate::TypeOutlives(..) |
ty::Predicate::ConstEvaluatable(..) => None,
}
})
.collect();
});

self.elaborate_bounds(&bounds, |this, poly_trait_ref, item| {
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);

let (xform_self_ty, xform_ret_ty) =
Expand All @@ -693,15 +693,16 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {

// Do a search through a list of bounds, using a callback to actually
// create the candidates.
fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
fn elaborate_bounds<F>(&mut self,
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
mut mk_cand: F)
where F: for<'b> FnMut(&mut ProbeContext<'b, 'gcx, 'tcx>,
ty::PolyTraitRef<'tcx>,
ty::AssociatedItem)
{
debug!("elaborate_bounds(bounds={:?})", bounds);

let tcx = self.tcx;
for bound_trait_ref in traits::transitive_bounds(tcx, 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) {
self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));
Expand Down

0 comments on commit 0cf957d

Please sign in to comment.