Make lifetime ordering error pretty print const param defaults

This commit is contained in:
Ellen 2021-05-29 03:54:32 +01:00
parent f58631b450
commit f208f207d6
4 changed files with 21 additions and 5 deletions

View File

@ -938,8 +938,11 @@ fn validate_generic_param_order(
}
GenericParamKind::Type { default: None } => (),
GenericParamKind::Lifetime => (),
// FIXME(const_generics_defaults)
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (),
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
ordered_params += " = ";
ordered_params += &pprust::expr_to_string(&*default.value);
}
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
}
first = false;
}
@ -959,7 +962,7 @@ fn validate_generic_param_order(
span,
&format!(
"reorder the parameters: lifetimes, {}",
if sess.features_untracked().const_generics {
if sess.features_untracked().unordered_const_ty_params() {
"then consts and types"
} else {
"then types, then consts"

View File

@ -2,13 +2,13 @@ error: lifetime parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:7:28
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
error: lifetime parameters must be declared prior to type parameters
--> $DIR/intermixed-lifetime.rs:10:37
|
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const N: usize, T = u32>`
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>`
error: aborting due to 2 previous errors

View File

@ -0,0 +1,5 @@
#![feature(const_generics_defaults)]
struct Foo<const M: usize = 10, 'a>(&'a u32);
//~^ Error lifetime parameters must be declared prior to const parameters
fn main() {}

View File

@ -0,0 +1,8 @@
error: lifetime parameters must be declared prior to const parameters
--> $DIR/param-order-err-pretty-prints-default.rs:2:33
|
LL | struct Foo<const M: usize = 10, 'a>(&'a u32);
| ----------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const M: usize = 10>`
error: aborting due to previous error