Skip to content

Commit

Permalink
create only one vector when winnowing candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Oct 14, 2018
1 parent a2b8829 commit 354a965
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/librustc/lib.rs
Expand Up @@ -71,6 +71,7 @@
#![feature(in_band_lifetimes)]
#![feature(macro_at_most_once_rep)]
#![feature(crate_visibility_modifier)]
#![feature(transpose_result)]

#![recursion_limit="512"]

Expand Down
11 changes: 4 additions & 7 deletions src/librustc/traits/select.rs
Expand Up @@ -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,
Expand All @@ -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 {:?}: {:?}",
Expand All @@ -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 {
Expand Down

0 comments on commit 354a965

Please sign in to comment.