1
Fork 0

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::Type { default: None } => (),
GenericParamKind::Lifetime => (), GenericParamKind::Lifetime => (),
// FIXME(const_generics_defaults) GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
GenericParamKind::Const { ty: _, kw_span: _, default: _ } => (), ordered_params += " = ";
ordered_params += &pprust::expr_to_string(&*default.value);
}
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
} }
first = false; first = false;
} }
@ -959,7 +962,7 @@ fn validate_generic_param_order(
span, span,
&format!( &format!(
"reorder the parameters: lifetimes, {}", "reorder the parameters: lifetimes, {}",
if sess.features_untracked().const_generics { if sess.features_untracked().unordered_const_ty_params() {
"then consts and types" "then consts and types"
} else { } else {
"then types, then consts" "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 --> $DIR/intermixed-lifetime.rs:7:28
| |
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T); 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 error: lifetime parameters must be declared prior to type parameters
--> $DIR/intermixed-lifetime.rs:10:37 --> $DIR/intermixed-lifetime.rs:10:37
| |
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T); 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 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