From f9d8bb8e2cb9a8ce7f8663c0a114cbc1a81209d4 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 21 Mar 2019 13:43:37 +0000 Subject: [PATCH] Simplify `fudge_inference_if_ok` --- src/librustc/infer/fudge.rs | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs index 198e0ce7381..f21fb603cb5 100644 --- a/src/librustc/infer/fudge.rs +++ b/src/librustc/infer/fudge.rs @@ -56,7 +56,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { { debug!("fudge_inference_if_ok(origin={:?})", origin); - let (type_vars, int_vars, float_vars, region_vars, value) = self.probe(|snapshot| { + let (mut fudger, value) = self.probe(|snapshot| { match f() { Ok(value) => { let value = self.resolve_type_vars_if_possible(&value); @@ -80,7 +80,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { &snapshot.region_constraints_snapshot, ); - Ok((type_vars, int_vars, float_vars, region_vars, value)) + let fudger = InferenceFudger { + infcx: self, + type_vars, + int_vars, + float_vars, + region_vars, + origin, + }; + + Ok((fudger, value)) } Err(e) => Err(e), } @@ -93,32 +102,23 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // Micro-optimization: if no variables have been created, then // `value` can't refer to any of them. =) So we can just return it. - if type_vars.is_empty() && - int_vars.is_empty() && - float_vars.is_empty() && - region_vars.is_empty() { + if fudger.type_vars.is_empty() && + fudger.int_vars.is_empty() && + fudger.float_vars.is_empty() && + fudger.region_vars.is_empty() { return Ok(value); } - let mut fudger = InferenceFudger { - infcx: self, - type_vars: &type_vars, - int_vars: &int_vars, - float_vars: &float_vars, - region_vars: ®ion_vars, - origin, - }; - Ok(value.fold_with(&mut fudger)) } } pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - type_vars: &'a Range, - int_vars: &'a Range, - float_vars: &'a Range, - region_vars: &'a Range, + type_vars: Range, + int_vars: Range, + float_vars: Range, + region_vars: Range, origin: &'a RegionVariableOrigin, }