Skip to content

Commit

Permalink
Clean match statement
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Aug 19, 2018
1 parent e79bc41 commit 6a96cf1
Showing 1 changed file with 27 additions and 31 deletions.
58 changes: 27 additions & 31 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,39 +274,35 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
// input. We try to handle both sensibly.
'args: for arg in &generic_args.args {
while let Some(param) = next_param {
match param.kind {
GenericParamDefKind::Lifetime => match arg {
GenericArg::Lifetime(_) => {
push_kind(&mut substs, provided_kind(param, arg));
next_param = params.next();
continue 'args;
}
GenericArg::Type(_) => {
// We expected a lifetime argument, but got a type
// argument. That means we're inferring the lifetimes.
push_kind(&mut substs, inferred_kind(None, param, infer_types));
next_param = params.next();
}
match (&param.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(_)) => {
push_kind(&mut substs, provided_kind(param, arg));
next_param = params.next();
continue 'args;
}
GenericParamDefKind::Type { .. } => match arg {
GenericArg::Type(_) => {
push_kind(&mut substs, provided_kind(param, arg));
next_param = params.next();
continue 'args;
}
GenericArg::Lifetime(_) => {
// We expected a type argument, but got a lifetime
// argument. This is an error, but we need to handle it
// gracefully so we can report sensible errors. In this
// case, we're simply going to infer the remaining
// arguments.
if err_if_invalid {
tcx.sess.delay_span_bug(span,
"found a GenericArg::Lifetime where a \
GenericArg::Type was expected");
}
break 'args;
(GenericParamDefKind::Lifetime, GenericArg::Type(_)) => {
// We expected a lifetime argument, but got a type
// argument. That means we're inferring the lifetimes.
push_kind(&mut substs, inferred_kind(None, param, infer_types));
next_param = params.next();
}
(GenericParamDefKind::Type { .. }, GenericArg::Type(_)) => {
push_kind(&mut substs, provided_kind(param, arg));
next_param = params.next();
continue 'args;
}
(GenericParamDefKind::Type { .. }, GenericArg::Lifetime(_)) => {
// We expected a type argument, but got a lifetime
// argument. This is an error, but we need to handle it
// gracefully so we can report sensible errors. In this
// case, we're simply going to infer the remaining
// arguments.
if err_if_invalid {
tcx.sess.delay_span_bug(span,
"found a GenericArg::Lifetime where a \
GenericArg::Type was expected");
}
break 'args;
}
}
}
Expand Down

0 comments on commit 6a96cf1

Please sign in to comment.