- // another. 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 this argument.
- args.next();
+ // another. This is an error. However, if we already know that
+ // the arguments don't match up with the parameters, we won't issue
+ // an additional error, as the user already knows what's wrong.
+ if !arg_count_mismatch {
+ let param_kind = match kind {
+ GenericParamDefKind::Lifetime => "lifetime",
+ GenericParamDefKind::Type { .. } => "type",
+ GenericParamDefKind::Const => "constant",
+ };
+ struct_span_err!(
+ tcx.sess,
+ arg.span(),
+ E0747,
+ "{} provided when a {} was expected",
+ arg_kind(arg),
+ param_kind,
+ )
+ .emit();
+ }
+
+ // We've reported the error, but we want to make sure that this
+ // problem doesn't bubble down and create additional, irrelevant
+ // errors. In this case, we're simply going to ignore the argument
+ // and any following arguments. The rest of the parameters will be
+ // inferred.
+ while args.next().is_some() {}