diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 0b7526dd78428..940cf736012ec 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -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>) -> 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) } @@ -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>) -> Supertraits<'cx, 'gcx, 'tcx> { elaborate_trait_refs(tcx, bounds).filter_to_traits() diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 1978f86545e7b..7ddc56974d816 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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(); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index c506f23078f25..2202c1d78476b 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -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; @@ -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) = @@ -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| { @@ -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) = @@ -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(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F) + fn elaborate_bounds(&mut self, + bounds: impl Iterator>, + 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()));