Skip to content

Commit 69a1ac3

Browse files
authored
Rollup merge of #72848 - camelid:fix-72815, r=varkor
Correct generic parameter ordering in error note for E0747 Fixes #72815. r? @varkor
2 parents 9c3ac0c + 56f87ef commit 69a1ac3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/librustc_typeck/astconv.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use crate::collect::PlaceholderHirTyCollector;
99
use crate::middle::resolve_lifetime as rl;
1010
use crate::require_c_abi_if_c_variadic;
11+
use rustc_ast::ast::ParamKindOrd;
1112
use rustc_ast::util::lev_distance::find_best_match_for_name;
1213
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1314
use rustc_errors::ErrorReported;
@@ -483,8 +484,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
483484
arg.descr(),
484485
kind,
485486
);
487+
488+
let kind_ord = match kind {
489+
"lifetime" => ParamKindOrd::Lifetime,
490+
"type" => ParamKindOrd::Type,
491+
"constant" => ParamKindOrd::Const,
492+
// It's more concise to match on the string representation, though it means
493+
// the match is non-exhaustive.
494+
_ => bug!("invalid generic parameter kind {}", kind),
495+
};
496+
let arg_ord = match arg {
497+
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
498+
GenericArg::Type(_) => ParamKindOrd::Type,
499+
GenericArg::Const(_) => ParamKindOrd::Const,
500+
};
501+
486502
// This note will be true as long as generic parameters are strictly ordered by their kind.
487-
err.note(&format!("{} arguments must be provided before {} arguments", kind, arg.descr()));
503+
let (first, last) =
504+
if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) };
505+
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
488506
err.emit();
489507
}
490508

src/test/ui/suggestions/suggest-move-types.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ error[E0747]: lifetime provided when a type was expected
124124
LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime<T, 'a, A=(), B=(), C=(), U, 'b, V, 'c>> {
125125
| ^^
126126
|
127-
= note: type arguments must be provided before lifetime arguments
127+
= note: lifetime arguments must be provided before type arguments
128128

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

137137
error: aborting due to 12 previous errors
138138

0 commit comments

Comments
 (0)