Skip to content

Commit 84edc0a

Browse files
committed
Move lifetime calculation outside loop
1 parent b6eef18 commit 84edc0a

File tree

1 file changed

+8
-8
lines changed
  • src/librustc_typeck/check

1 file changed

+8
-8
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,14 +4951,19 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49514951
let supress_mismatch = self.check_impl_trait(span, seg, &generics);
49524952
supress_errors.insert(index,
49534953
self.check_generic_arg_count(span, seg, &generics, false, supress_mismatch));
4954-
infer_lifetimes.insert(index, if let Some(ref data) = seg.args {
4954+
let inferred_lifetimes = if if let Some(ref data) = seg.args {
49554955
!data.args.iter().any(|arg| match arg {
49564956
GenericArg::Lifetime(_) => true,
49574957
_ => false,
49584958
})
49594959
} else {
49604960
true
4961-
});
4961+
} {
4962+
generics.own_counts().lifetimes
4963+
} else {
4964+
0
4965+
};
4966+
infer_lifetimes.insert(index, inferred_lifetimes);
49624967
}
49634968

49644969
let has_self = path_segs.last().map(|PathSeg(def_id, _)| {
@@ -4997,15 +5002,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49975002
true
49985003
} else {
49995004
if let Some(ref data) = segments[index].args {
5000-
let lifetime_offset = if infer_lifetimes[&index] {
5001-
defs.own_counts().lifetimes
5002-
} else {
5003-
0
5004-
};
50055005
let self_offset = (defs.parent_count == 0 && has_self) as usize;
50065006
let param_idx =
50075007
(param.index as usize - defs.parent_count - self_offset as usize)
5008-
.saturating_sub(lifetime_offset);
5008+
.saturating_sub(infer_lifetimes[&index]);
50095009
if let Some(arg) = data.args.get(param_idx) {
50105010
match param.kind {
50115011
GenericParamDefKind::Lifetime => match arg {

0 commit comments

Comments
 (0)