Skip to content

Commit 0cf957d

Browse files
authored
Rollup merge of rust-lang#55473 - ljedrz:transitive/elaborate_bounds_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.
2 parents dc04aaf + 40079ac commit 0cf957d

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/librustc/traits/util.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ pub fn elaborate_trait_ref<'cx, 'gcx, 'tcx>(
103103

104104
pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>(
105105
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
106-
trait_refs: &[ty::PolyTraitRef<'tcx>])
106+
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
107107
-> Elaborator<'cx, 'gcx, 'tcx>
108108
{
109-
let predicates = trait_refs.iter()
110-
.map(|trait_ref| trait_ref.to_predicate())
109+
let predicates = trait_refs.map(|trait_ref| trait_ref.to_predicate())
111110
.collect();
112111
elaborate_predicates(tcx, predicates)
113112
}
@@ -271,7 +270,7 @@ pub fn supertraits<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
271270
}
272271

273272
pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
274-
bounds: &[ty::PolyTraitRef<'tcx>])
273+
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
275274
-> Supertraits<'cx, 'gcx, 'tcx>
276275
{
277276
elaborate_trait_refs(tcx, bounds).filter_to_traits()

src/librustc_typeck/astconv.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1112,12 +1112,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
11121112
{
11131113
let tcx = self.tcx();
11141114

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

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

11231123
let param_node_id = tcx.hir.as_local_node_id(ty_param_def_id).unwrap();

src/librustc_typeck/check/method/probe.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc::middle::stability;
3131
use syntax::ast;
3232
use syntax::util::lev_distance::{lev_distance, find_best_match_for_name};
3333
use syntax_pos::{Span, symbol::Symbol};
34+
use std::iter;
3435
use std::mem;
3536
use std::ops::Deref;
3637
use std::rc::Rc;
@@ -627,7 +628,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
627628
// itself. Hence, a `&self` method will wind up with an
628629
// argument type like `&Trait`.
629630
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
630-
self.elaborate_bounds(&[trait_ref], |this, new_trait_ref, item| {
631+
self.elaborate_bounds(iter::once(trait_ref), |this, new_trait_ref, item| {
631632
let new_trait_ref = this.erase_late_bound_regions(&new_trait_ref);
632633

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

648-
let bounds: Vec<_> = self.param_env
649+
let bounds = self.param_env
649650
.caller_bounds
650651
.iter()
651652
.filter_map(|predicate| {
@@ -667,10 +668,9 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
667668
ty::Predicate::TypeOutlives(..) |
668669
ty::Predicate::ConstEvaluatable(..) => None,
669670
}
670-
})
671-
.collect();
671+
});
672672

673-
self.elaborate_bounds(&bounds, |this, poly_trait_ref, item| {
673+
self.elaborate_bounds(bounds, |this, poly_trait_ref, item| {
674674
let trait_ref = this.erase_late_bound_regions(&poly_trait_ref);
675675

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

694694
// Do a search through a list of bounds, using a callback to actually
695695
// create the candidates.
696-
fn elaborate_bounds<F>(&mut self, bounds: &[ty::PolyTraitRef<'tcx>], mut mk_cand: F)
696+
fn elaborate_bounds<F>(&mut self,
697+
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
698+
mut mk_cand: F)
697699
where F: for<'b> FnMut(&mut ProbeContext<'b, 'gcx, 'tcx>,
698700
ty::PolyTraitRef<'tcx>,
699701
ty::AssociatedItem)
700702
{
701-
debug!("elaborate_bounds(bounds={:?})", bounds);
702-
703703
let tcx = self.tcx;
704704
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
705+
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
705706
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
706707
if !self.has_applicable_self(&item) {
707708
self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));

0 commit comments

Comments
 (0)