Skip to content

Commit 2317abd

Browse files
committed
Fix quadratic loop in confirm.rs
1 parent 651215e commit 2317abd

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ impl<'a, 'tcx, 'cl> Visitor<'tcx> for Resolver<'a, 'cl> {
824824
GenericParamKind::Type { ref default, .. } => {
825825
found_default |= default.is_some();
826826
if found_default {
827-
Some((Ident::with_empty_ctxt(param.ident.name), Def::Err));
827+
Some((Ident::with_empty_ctxt(param.ident.name), Def::Err))
828828
} else {
829829
None
830830
}

src/librustc_typeck/check/method/confirm.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -324,37 +324,34 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
324324
assert_eq!(method_generics.parent_count, parent_substs.len());
325325
let provided = &segment.args;
326326
let own_counts = method_generics.own_counts();
327+
// FIXME(varkor): Separating out the parameters is messy.
328+
let lifetimes: Vec<_> = provided.iter().flat_map(|data| data.args.iter().filter_map(|arg| match arg {
329+
GenericArg::Lifetime(ty) => Some(ty),
330+
_ => None,
331+
})).collect();
332+
let types: Vec<_> = provided.iter().flat_map(|data| data.args.iter().filter_map(|arg| match arg {
333+
GenericArg::Type(ty) => Some(ty),
334+
_ => None,
335+
})).collect();
327336
Substs::for_item(self.tcx, pick.item.def_id, |param, _| {
328-
let mut i = param.index as usize;
337+
let i = param.index as usize;
329338
if i < parent_substs.len() {
330339
parent_substs[i]
331340
} else {
332-
let (is_lt, is_ty) = match param.kind {
333-
GenericParamDefKind::Lifetime => (true, false),
334-
GenericParamDefKind::Type { .. } => (false, true),
335-
};
336-
provided.as_ref().and_then(|data| {
337-
for arg in &data.args {
338-
match arg {
339-
GenericArg::Lifetime(lt) if is_lt => {
340-
if i == parent_substs.len() {
341-
return Some(AstConv::ast_region_to_region(
342-
self.fcx, lt, Some(param)).into());
343-
}
344-
i -= 1;
345-
}
346-
GenericArg::Lifetime(_) => {}
347-
GenericArg::Type(ty) if is_ty => {
348-
if i == parent_substs.len() + own_counts.lifetimes {
349-
return Some(self.to_ty(ty).into());
350-
}
351-
i -= 1;
352-
}
353-
GenericArg::Type(_) => {}
341+
match param.kind {
342+
GenericParamDefKind::Lifetime => {
343+
if let Some(lifetime) = lifetimes.get(i - parent_substs.len()) {
344+
return AstConv::ast_region_to_region(
345+
self.fcx, lifetime, Some(param)).into();
354346
}
355347
}
356-
None
357-
}).unwrap_or_else(|| self.var_for_def(self.span, param))
348+
GenericParamDefKind::Type { .. } => {
349+
if let Some(ast_ty) = types.get(i - parent_substs.len() - own_counts.lifetimes) {
350+
return self.to_ty(ast_ty).into();
351+
}
352+
}
353+
}
354+
self.var_for_def(self.span, param)
358355
}
359356
})
360357
}

0 commit comments

Comments
 (0)