From b44d94a5162ee4b2e20f4ae82328f3e7f6a152b8 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 7 Aug 2016 06:41:17 -0400 Subject: [PATCH] remove unneccessary uses of `drain_fulfillment_cx` There were various places that we are invoking `drain_fulfillment_cx` with a "result" of `()`. This is kind of pointless, since it amounts to just a call to `select_all_or_error` along with some extra overhead. --- src/librustc/traits/specialize/mod.rs | 35 +++++++++++++++------------ src/librustc_trans/common.rs | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 9acfe2754820..0604136ec601 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -207,24 +207,27 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, for oblig in obligations.into_iter() { fulfill_cx.register_predicate_obligation(&infcx, oblig); } + match fulfill_cx.select_all_or_error(infcx) { + Err(errors) => { + // no dice! + debug!("fulfill_implication: for impls on {:?} and {:?}, could not fulfill: {:?} given \ + {:?}", + source_trait_ref, + target_trait_ref, + errors, + infcx.parameter_environment.caller_bounds); + Err(()) + } - if let Err(errors) = infcx.drain_fulfillment_cx(&mut fulfill_cx, &()) { - // no dice! - debug!("fulfill_implication: for impls on {:?} and {:?}, could not fulfill: {:?} given \ - {:?}", - source_trait_ref, - target_trait_ref, - errors, - infcx.parameter_environment.caller_bounds); - Err(()) - } else { - debug!("fulfill_implication: an impl for {:?} specializes {:?}", - source_trait_ref, - target_trait_ref); + Ok(()) => { + debug!("fulfill_implication: an impl for {:?} specializes {:?}", + source_trait_ref, + target_trait_ref); - // Now resolve the *substitution* we built for the target earlier, replacing - // the inference variables inside with whatever we got from fulfillment. - Ok(infcx.resolve_type_vars_if_possible(&target_substs)) + // Now resolve the *substitution* we built for the target earlier, replacing + // the inference variables inside with whatever we got from fulfillment. + Ok(infcx.resolve_type_vars_if_possible(&target_substs)) + } } } diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index d5dcae5f6b0a..95a38cd21d93 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -1028,7 +1028,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fulfill_cx.register_predicate_obligation(&infcx, obligation); } - infcx.drain_fulfillment_cx(&mut fulfill_cx, &()).is_ok() + fulfill_cx.select_all_or_error(infcx).is_ok() }) }