diff options
| author | bors <bors@rust-lang.org> | 2018-10-16 07:04:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-10-16 07:04:10 +0000 |
| commit | 5ea8eb55cd9f4547b332f43c9f723de30187c223 (patch) | |
| tree | df2da6dfb48859b7b70894116893ba1b2b5b18f2 /src/librustc/traits | |
| parent | df0d6ad9c1510630b234f6bb96a69a081de0b307 (diff) | |
| parent | a14a950c44ec6a2a4ed38e0b133c35e2245d194a (diff) | |
| download | rust-5ea8eb55cd9f4547b332f43c9f723de30187c223.tar.gz rust-5ea8eb55cd9f4547b332f43c9f723de30187c223.zip | |
Auto merge of #55067 - ljedrz:generic_iterator_related_improvements, r=petrochenkov
A few iterator-related improvements - typeck: don't collect into a vector when unnecessary - create only one vector when winnowing candidates - change a cloning map to `into_iter`
Diffstat (limited to 'src/librustc/traits')
| -rw-r--r-- | src/librustc/traits/select.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 8e8024e51da..156a27a7d0a 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -1368,8 +1368,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { // Winnow, but record the exact outcome of evaluation, which // is needed for specialization. Propagate overflow if it occurs. - let candidates: Result<Vec<Option<EvaluatedCandidate<'_>>>, _> = candidates - .into_iter() + let mut candidates = candidates.into_iter() .map(|c| match self.evaluate_candidate(stack, &c) { Ok(eval) if eval.may_apply() => Ok(Some(EvaluatedCandidate { candidate: c, @@ -1378,10 +1377,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { Ok(_) => Ok(None), Err(OverflowError) => Err(Overflow), }) - .collect(); - - let mut candidates: Vec<EvaluatedCandidate<'_>> = - candidates?.into_iter().filter_map(|c| c).collect(); + .flat_map(Result::transpose) + .collect::<Result<Vec<_>, _>>()?; debug!( "winnowed to {} candidates for {:?}: {:?}", @@ -1390,7 +1387,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { candidates ); - // If there are STILL multiple candidate, we can further + // If there are STILL multiple candidates, we can further // reduce the list by dropping duplicates -- including // resolving specializations. if candidates.len() > 1 { |
