Added +1 test for only works w/ feat const gen

Added this test to ensure that reordering the parameters only works with the feature const
generics enabled.

Fixed nits

Also added another test to verify that intermixed lifetimes are forbidden
This commit is contained in:
kadmin 2020-07-30 18:43:44 +00:00
parent 18481cbec9
commit f8588284af
7 changed files with 59 additions and 3 deletions

View File

@ -735,8 +735,11 @@ fn validate_generic_param_order<'a>(
}
let max_param = &mut max_param;
match max_param {
Some(ParamKindOrd::Const) if ParamKindOrd::Type == kind &&
sess.features_untracked().const_generics => (),
Some(ParamKindOrd::Const)
if ParamKindOrd::Type == kind && sess.features_untracked().const_generics =>
{
()
}
Some(max_param) if *max_param > kind => {
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
entry.1.push(span);

View File

@ -0,0 +1,9 @@
// Checks that lifetimes cannot be interspersed between consts and types.
#![feature(const_generics)]
#![allow(incomplete_features)]
struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
//~^ 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/intermixed-lifetime.rs:6:28
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
error: aborting due to previous error

View File

@ -0,0 +1,8 @@
// Verifies that having generic parameters after constants is not permitted without the
// `const_generics` feature.
struct A<const N: usize, T=u32>(T);
//~^ ERROR type parameters must be declared prior
//~| ERROR const generics are unstable
fn main() {}

View File

@ -0,0 +1,18 @@
error: type parameters must be declared prior to const parameters
--> $DIR/needs-feature.rs:4:26
|
LL | struct A<const N: usize, T=u32>(T);
| -----------------^----- help: reorder the parameters: lifetimes, then types: `<T, const N: usize>`
error[E0658]: const generics are unstable
--> $DIR/needs-feature.rs:4:16
|
LL | struct A<const N: usize, T=u32>(T);
| ^
|
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
= help: add `#![feature(const_generics)]` to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.

View File

@ -1,5 +1,5 @@
// run-pass
// Verifies that having generic parameters after constants is permitted
// Verifies that having generic parameters after constants is permitted.
#![feature(const_generics)]
#![allow(incomplete_features)]

View File

@ -0,0 +1,10 @@
// run-pass
// Verifies that having generic parameters after constants is permitted
#![feature(const_generics)]
#![allow(incomplete_features)]
#[allow(dead_code)]
struct A<const N: usize, T>(T);
fn main() {}