// 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;
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,
) {
if !first {
ordered_params += ", ";
}
- ordered_params += &ident.as_str();
+ ordered_params += &ident;
first = false;
}
}
}
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 {
--> $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