From e02642dbb32dff0c0c2294f6953975e3e04ef696 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 3 Jul 2018 19:55:28 +0100 Subject: [PATCH] Fix confirm.rs --- src/librustc_typeck/check/method/confirm.rs | 22 +++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index aa2147e9450..c9ac02928b3 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -323,12 +323,26 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // parameters from the type and those from the method. assert_eq!(method_generics.parent_count, parent_substs.len()); + let inferred_lifetimes = if if let Some(ref data) = segment.args { + !data.args.iter().any(|arg| match arg { + GenericArg::Lifetime(_) => true, + _ => false, + }) + } else { + true + } { + method_generics.own_counts().lifetimes + } else { + 0 + }; + Substs::for_item(self.tcx, pick.item.def_id, |param, _| { - let i = param.index as usize; - if i < parent_substs.len() { - parent_substs[i] + let param_idx = param.index as usize; + if param_idx < parent_substs.len() { + parent_substs[param_idx] } else { - let param_idx = i - parent_substs.len(); + let param_idx = (param.index as usize - parent_substs.len()) + .saturating_sub(inferred_lifetimes); if let Some(ref data) = segment.args { if let Some(arg) = data.args.get(param_idx) {