Skip to content

Commit 7461a5e

Browse files
committed
Fix ast_validation printing of const generics
1 parent 1805546 commit 7461a5e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/librustc_passes/ast_validation.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// or type checking or some other kind of complex analysis.
88

99
use std::mem;
10+
use syntax::print::pprust;
1011
use rustc::lint;
1112
use rustc::session::Session;
1213
use rustc_data_structures::fx::FxHashMap;
@@ -281,7 +282,7 @@ enum GenericPosition {
281282

282283
fn validate_generics_order<'a>(
283284
handler: &errors::Handler,
284-
generics: impl Iterator<Item = (ParamKindOrd, Span, Option<Ident>)>,
285+
generics: impl Iterator<Item = (ParamKindOrd, Span, Option<String>)>,
285286
pos: GenericPosition,
286287
span: Span,
287288
) {
@@ -311,7 +312,7 @@ fn validate_generics_order<'a>(
311312
if !first {
312313
ordered_params += ", ";
313314
}
314-
ordered_params += &ident.as_str();
315+
ordered_params += &ident;
315316
first = false;
316317
}
317318
}
@@ -635,11 +636,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
635636
}
636637

637638
validate_generics_order(self.err_handler(), generics.params.iter().map(|param| {
638-
(match param.kind {
639-
GenericParamKind::Lifetime { .. } => ParamKindOrd::Lifetime,
640-
GenericParamKind::Type { .. } => ParamKindOrd::Type,
641-
GenericParamKind::Const { .. } => ParamKindOrd::Const,
642-
}, param.ident.span, Some(param.ident))
639+
let span = param.ident.span;
640+
let ident = Some(param.ident.to_string());
641+
match &param.kind {
642+
GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, span, ident),
643+
GenericParamKind::Type { .. } => (ParamKindOrd::Type, span, ident),
644+
GenericParamKind::Const { ref ty } => {
645+
let ty = pprust::ty_to_string(ty);
646+
(ParamKindOrd::Const, span, Some(format!("const {}: {}", param.ident, ty)))
647+
}
648+
}
643649
}), GenericPosition::Param, generics.span);
644650

645651
for predicate in &generics.where_clause.predicates {

src/test/ui/const-generics/const-param-before-other-params.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ error: type parameters must be declared prior to const parameters
88
--> $DIR/const-param-before-other-params.rs:4:21
99
|
1010
LL | fn foo<const X: (), T>(_: T) {
11-
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, X>`
11+
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
1212

1313
error: lifetime parameters must be declared prior to const parameters
1414
--> $DIR/const-param-before-other-params.rs:9:21
1515
|
1616
LL | fn bar<const X: (), 'a>(_: &'a ()) {
17-
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, X>`
17+
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
1818

1919
error: const generics in any position are currently unsupported
2020
--> $DIR/const-param-before-other-params.rs:4:14

0 commit comments

Comments
 (0)