]> git.lizzy.rs Git - rust.git/commitdiff
Correct generic parameter ordering in error note
authorcamelid <camelidcamel@gmail.com>
Mon, 1 Jun 2020 03:45:08 +0000 (20:45 -0700)
committercamelid <camelidcamel@gmail.com>
Mon, 1 Jun 2020 03:45:08 +0000 (20:45 -0700)
src/librustc_typeck/astconv.rs
src/test/ui/suggestions/suggest-move-types.stderr

index ab9db159038af09b5187dbe897006a5ef8d660a0..9b47c4c7dde700b11c0096fce401d86eea789924 100644 (file)
@@ -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 @@ fn generic_arg_mismatch_err(sess: &Session, arg: &GenericArg<'_>, kind: &'static
             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();
     }
 
index 3bb6fd6e4f423587337a3b60fb28cb1169da9320..96f1656bae4ac321c6b2cbfdb4149e3ed7744635 100644 (file)
@@ -124,7 +124,7 @@ 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
@@ -132,7 +132,7 @@ error[E0747]: lifetime provided when a type was expected
 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