Rm restriction on ord of default types w/ consts
This commit is contained in:
parent
58b1a04b9e
commit
18481cbec9
6 changed files with 20 additions and 38 deletions
|
|
@ -735,7 +735,8 @@ fn validate_generic_param_order<'a>(
|
|||
}
|
||||
let max_param = &mut max_param;
|
||||
match max_param {
|
||||
Some(ParamKindOrd::Const) if ParamKindOrd::Type == kind => (),
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct Bad<const N: usize, T> { //~ ERROR type parameters must be declared prior
|
||||
struct Bad<const N: usize, T> {
|
||||
arr: [u8; { N }],
|
||||
another: T,
|
||||
}
|
||||
|
||||
struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
//~^ ERROR type parameters must be declared prior
|
||||
//~| ERROR lifetime parameters must be declared prior
|
||||
//~^ ERROR lifetime parameters must be declared prior
|
||||
a: &'a T,
|
||||
b: &'b U,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,11 @@
|
|||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:4:28
|
||||
|
|
||||
LL | struct Bad<const N: usize, T> {
|
||||
| -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>`
|
||||
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:9:32
|
||||
|
|
||||
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
|
||||
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:9:36
|
||||
|
|
||||
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
| ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
|
||||
|
||||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/argument_order.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error[E0747]: lifetime provided when a type was expected
|
||||
--> $DIR/argument_order.rs:17:23
|
||||
--> $DIR/argument_order.rs:16:23
|
||||
|
|
||||
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
|
||||
| ^^^^^^^
|
||||
|
|
@ -34,6 +13,6 @@ LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
|
|||
= note: lifetime arguments must be provided before type arguments
|
||||
= help: reorder the arguments: lifetimes, then types, then consts: `<'a, 'b, T, U, N, M>`
|
||||
|
||||
error: aborting due to 4 previous errors; 1 warning emitted
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0747`.
|
||||
|
|
|
|||
|
|
@ -5,8 +5,6 @@ fn bar<const X: (), 'a>(_: &'a ()) {
|
|||
//~^ ERROR lifetime parameters must be declared prior to const parameters
|
||||
}
|
||||
|
||||
fn foo<const X: (), T>(_: &T) {
|
||||
//~^ ERROR type parameters must be declared prior to const parameters
|
||||
}
|
||||
fn foo<const X: (), T>(_: &T) {}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,5 @@ error: lifetime parameters must be declared prior to const parameters
|
|||
LL | fn bar<const X: (), 'a>(_: &'a ()) {
|
||||
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
|
||||
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/const-param-before-other-params.rs:8:21
|
||||
|
|
||||
LL | fn foo<const X: (), T>(_: &T) {
|
||||
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
11
src/test/ui/const-generics/defaults/right-order.rs
Normal file
11
src/test/ui/const-generics/defaults/right-order.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// run-pass
|
||||
// Verifies that having generic parameters after constants is permitted
|
||||
|
||||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
struct A<const N: usize, T=u32>(T);
|
||||
|
||||
fn main() {
|
||||
let _: A<3> = A(0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue