]> git.lizzy.rs Git - rust.git/commitdiff
Fix ast_validation printing of const generics
authorvarkor <github@varkor.com>
Tue, 5 Feb 2019 18:00:07 +0000 (19:00 +0100)
committervarkor <github@varkor.com>
Thu, 7 Feb 2019 14:02:17 +0000 (15:02 +0100)
src/librustc_passes/ast_validation.rs
src/test/ui/const-generics/const-param-before-other-params.stderr

index 502799900642dd0b74260cfaea0c3ba1205d375a..a1c9d3ece2c0dee9844279b75a41438d84893843 100644 (file)
@@ -7,6 +7,7 @@
 // or type checking or some other kind of complex analysis.
 
 use std::mem;
+use syntax::print::pprust;
 use rustc::lint;
 use rustc::session::Session;
 use rustc_data_structures::fx::FxHashMap;
@@ -281,7 +282,7 @@ enum GenericPosition {
 
 fn validate_generics_order<'a>(
     handler: &errors::Handler,
-    generics: impl Iterator<Item = (ParamKindOrd, Span, Option<Ident>)>,
+    generics: impl Iterator<Item = (ParamKindOrd, Span, Option<String>)>,
     pos: GenericPosition,
     span: Span,
 ) {
@@ -311,7 +312,7 @@ fn validate_generics_order<'a>(
             if !first {
                 ordered_params += ", ";
             }
-            ordered_params += &ident.as_str();
+            ordered_params += &ident;
             first = false;
         }
     }
@@ -635,11 +636,16 @@ fn visit_generics(&mut self, generics: &'a Generics) {
         }
 
         validate_generics_order(self.err_handler(), generics.params.iter().map(|param| {
-            (match param.kind {
-                GenericParamKind::Lifetime { .. } => ParamKindOrd::Lifetime,
-                GenericParamKind::Type { .. } => ParamKindOrd::Type,
-                GenericParamKind::Const { .. } => ParamKindOrd::Const,
-            }, param.ident.span, Some(param.ident))
+            let span = param.ident.span;
+            let ident = Some(param.ident.to_string());
+            match &param.kind {
+                GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, span, ident),
+                GenericParamKind::Type { .. } => (ParamKindOrd::Type, span, ident),
+                GenericParamKind::Const { ref ty } => {
+                    let ty = pprust::ty_to_string(ty);
+                    (ParamKindOrd::Const, span, Some(format!("const {}: {}", param.ident, ty)))
+                }
+            }
         }), GenericPosition::Param, generics.span);
 
         for predicate in &generics.where_clause.predicates {
index 303ea16ca837a70ece4859753428691e725b6b0e..aedcaf52e2688a34deb25296b008a8f6fefc801a 100644 (file)
@@ -8,13 +8,13 @@ error: type parameters must be declared prior to const parameters
   --> $DIR/const-param-before-other-params.rs:4:21
    |
 LL | fn foo<const X: (), T>(_: T) {
-   |       --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, X>`
+   |       --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
 
 error: lifetime parameters must be declared prior to const parameters
   --> $DIR/const-param-before-other-params.rs:9:21
    |
 LL | fn bar<const X: (), 'a>(_: &'a ()) {
-   |       --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, X>`
+   |       --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
 
 error: const generics in any position are currently unsupported
   --> $DIR/const-param-before-other-params.rs:4:14