From 7461a5e655825294682b1d7d9a96aa2524dc7077 Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 5 Feb 2019 19:00:07 +0100 Subject: [PATCH] Fix ast_validation printing of const generics --- src/librustc_passes/ast_validation.rs | 20 ++++++++++++------- .../const-param-before-other-params.stderr | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 50279990064..a1c9d3ece2c 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -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)>, + generics: impl Iterator)>, 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 ¶m.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 { diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 303ea16ca83..aedcaf52e26 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -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(_: T) { - | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `` + | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `` error: lifetime parameters must be declared prior to const parameters --> $DIR/const-param-before-other-params.rs:9:21 | LL | fn bar(_: &'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 -- 2.44.0