From 84edc0a089d164ffc121d0566358718046c4a06d Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 3 Jul 2018 16:14:43 +0100 Subject: [PATCH] Move lifetime calculation outside loop --- src/librustc_typeck/check/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 87c9511019a5..8286004c2679 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4951,14 +4951,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let supress_mismatch = self.check_impl_trait(span, seg, &generics); supress_errors.insert(index, self.check_generic_arg_count(span, seg, &generics, false, supress_mismatch)); - infer_lifetimes.insert(index, if let Some(ref data) = seg.args { + let inferred_lifetimes = if if let Some(ref data) = seg.args { !data.args.iter().any(|arg| match arg { GenericArg::Lifetime(_) => true, _ => false, }) } else { true - }); + } { + generics.own_counts().lifetimes + } else { + 0 + }; + infer_lifetimes.insert(index, inferred_lifetimes); } let has_self = path_segs.last().map(|PathSeg(def_id, _)| { @@ -4997,15 +5002,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { true } else { if let Some(ref data) = segments[index].args { - let lifetime_offset = if infer_lifetimes[&index] { - defs.own_counts().lifetimes - } else { - 0 - }; let self_offset = (defs.parent_count == 0 && has_self) as usize; let param_idx = (param.index as usize - defs.parent_count - self_offset as usize) - .saturating_sub(lifetime_offset); + .saturating_sub(infer_lifetimes[&index]); if let Some(arg) = data.args.get(param_idx) { match param.kind { GenericParamDefKind::Lifetime => match arg {