Skip to content

Commit 354a965

Browse files
committed
create only one vector when winnowing candidates
1 parent a2b8829 commit 354a965

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

Diff for: src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#![feature(in_band_lifetimes)]
7272
#![feature(macro_at_most_once_rep)]
7373
#![feature(crate_visibility_modifier)]
74+
#![feature(transpose_result)]
7475

7576
#![recursion_limit="512"]
7677

Diff for: src/librustc/traits/select.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1368,8 +1368,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13681368

13691369
// Winnow, but record the exact outcome of evaluation, which
13701370
// is needed for specialization. Propagate overflow if it occurs.
1371-
let candidates: Result<Vec<Option<EvaluatedCandidate<'_>>>, _> = candidates
1372-
.into_iter()
1371+
let mut candidates = candidates.into_iter()
13731372
.map(|c| match self.evaluate_candidate(stack, &c) {
13741373
Ok(eval) if eval.may_apply() => Ok(Some(EvaluatedCandidate {
13751374
candidate: c,
@@ -1378,10 +1377,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13781377
Ok(_) => Ok(None),
13791378
Err(OverflowError) => Err(Overflow),
13801379
})
1381-
.collect();
1382-
1383-
let mut candidates: Vec<EvaluatedCandidate<'_>> =
1384-
candidates?.into_iter().filter_map(|c| c).collect();
1380+
.flat_map(Result::transpose)
1381+
.collect::<Result<Vec<_>, _>>()?;
13851382

13861383
debug!(
13871384
"winnowed to {} candidates for {:?}: {:?}",
@@ -1390,7 +1387,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
13901387
candidates
13911388
);
13921389

1393-
// If there are STILL multiple candidate, we can further
1390+
// If there are STILL multiple candidates, we can further
13941391
// reduce the list by dropping duplicates -- including
13951392
// resolving specializations.
13961393
if candidates.len() > 1 {

0 commit comments

Comments
 (0)