From 354a965ede0d63e81964b16276e4a1a6b1bbcdc5 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Sun, 14 Oct 2018 14:17:32 +0200 Subject: [PATCH] create only one vector when winnowing candidates --- src/librustc/lib.rs | 1 + src/librustc/traits/select.rs | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 5519330a3742..3c2caa39d76e 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -71,6 +71,7 @@ #![feature(in_band_lifetimes)] #![feature(macro_at_most_once_rep)] #![feature(crate_visibility_modifier)] +#![feature(transpose_result)] #![recursion_limit="512"] diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 82d881e10b16..9029486b5c96 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>>, _> = 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> = - candidates?.into_iter().filter_map(|c| c).collect(); + .flat_map(Result::transpose) + .collect::, _>>()?; 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 {