Skip to content

Commit

Permalink
Rollup merge of #72848 - camelid:fix-72815, r=varkor
Browse files Browse the repository at this point in the history
Correct generic parameter ordering in error note for E0747

Fixes #72815.

r? @varkor
  • Loading branch information
Dylan-DPC authored Jun 3, 2020
2 parents 9c3ac0c + 56f87ef commit 69a1ac3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 19 additions & 1 deletion src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use crate::collect::PlaceholderHirTyCollector;
use crate::middle::resolve_lifetime as rl;
use crate::require_c_abi_if_c_variadic;
use rustc_ast::ast::ParamKindOrd;
use rustc_ast::util::lev_distance::find_best_match_for_name;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorReported;
Expand Down Expand Up @@ -483,8 +484,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
arg.descr(),
kind,
);

let kind_ord = match kind {
"lifetime" => ParamKindOrd::Lifetime,
"type" => ParamKindOrd::Type,
"constant" => ParamKindOrd::Const,
// It's more concise to match on the string representation, though it means
// the match is non-exhaustive.
_ => bug!("invalid generic parameter kind {}", kind),
};
let arg_ord = match arg {
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
GenericArg::Type(_) => ParamKindOrd::Type,
GenericArg::Const(_) => ParamKindOrd::Const,
};

// This note will be true as long as generic parameters are strictly ordered by their kind.
err.note(&format!("{} arguments must be provided before {} arguments", kind, arg.descr()));
let (first, last) =
if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) };
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
err.emit();
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/suggestions/suggest-move-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ error[E0747]: lifetime provided when a type was expected
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
| ^^
|
= note: type arguments must be provided before lifetime arguments
= note: lifetime arguments must be provided before type arguments

error[E0747]: lifetime provided when a type was expected
--> $DIR/suggest-move-types.rs:82:56
|
LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), U, 'b, C=(), V, 'c>> {
| ^^
|
= note: type arguments must be provided before lifetime arguments
= note: lifetime arguments must be provided before type arguments

error: aborting due to 12 previous errors

Expand Down

0 comments on commit 69a1ac3

Please sign in to comment.