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:
parent
18481cbec9
commit
f8588284af
@ -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);
|
||||
|
@ -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() {}
|
@ -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
|
||||
|
8
src/test/ui/const-generics/defaults/needs-feature.rs
Normal file
8
src/test/ui/const-generics/defaults/needs-feature.rs
Normal 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() {}
|
18
src/test/ui/const-generics/defaults/needs-feature.stderr
Normal file
18
src/test/ui/const-generics/defaults/needs-feature.stderr
Normal 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`.
|
@ -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)]
|
||||
|
@ -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() {}
|
Loading…
x
Reference in New Issue
Block a user