From 718d28cf85305411bdad8e3b2a4f932bd9f628c7 Mon Sep 17 00:00:00 2001 From: camelid Date: Sun, 31 May 2020 20:45:08 -0700 Subject: [PATCH 1/3] Correct generic parameter ordering in error note --- src/librustc_typeck/astconv.rs | 18 +++++++++++++++++- .../ui/suggestions/suggest-move-types.stderr | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index ab9db159038af..9b47c4c7dde70 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -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; @@ -483,8 +484,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg.descr(), kind, ); + + let kind_ord = match kind { + "lifetime" => ParamKindOrd::Lifetime, + "type" => ParamKindOrd::Type, + "constant" => ParamKindOrd::Const, + _ => panic!(), + }; + 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(); } diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 3bb6fd6e4f423..96f1656bae4ac 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -124,7 +124,7 @@ error[E0747]: lifetime provided when a type was expected LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime> { | ^^ | - = 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 @@ -132,7 +132,7 @@ error[E0747]: lifetime provided when a type was expected LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime> { | ^^ | - = 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 From fd76d236e42378d0feaf5df6dbdbd2db89ba0f1f Mon Sep 17 00:00:00 2001 From: Camelid <37223377+camelid@users.noreply.github.com> Date: Mon, 1 Jun 2020 10:52:07 -0700 Subject: [PATCH 2/3] Use `bug!` instead of `panic!` Co-authored-by: varkor --- src/librustc_typeck/astconv.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 9b47c4c7dde70..7173ed3d24ec8 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -489,7 +489,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { "lifetime" => ParamKindOrd::Lifetime, "type" => ParamKindOrd::Type, "constant" => ParamKindOrd::Const, - _ => panic!(), + // It's more concise to match on the string representation, though it means + // the match is non-exhaustive. + _ => bug!("invalid generic parameter kind"), }; let arg_ord = match arg { GenericArg::Lifetime(_) => ParamKindOrd::Lifetime, From 56f87efa2c587539ea1e7f22e2feff5107429aae Mon Sep 17 00:00:00 2001 From: Camelid <37223377+camelid@users.noreply.github.com> Date: Mon, 1 Jun 2020 13:01:01 -0700 Subject: [PATCH 3/3] Include kind in `bug!` Co-authored-by: hafiz <20735482+ayazhafiz@users.noreply.github.com> --- src/librustc_typeck/astconv.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 7173ed3d24ec8..f1dc7e5390629 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -491,7 +491,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { "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"), + _ => bug!("invalid generic parameter kind {}", kind), }; let arg_ord = match arg { GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,