From 18481cbec981f320abfb83df0e96fd127def7cd5 Mon Sep 17 00:00:00 2001 From: kadmin Date: Thu, 30 Jul 2020 18:39:53 +0000 Subject: [PATCH] Rm restriction on ord of default types w/ consts --- src/librustc_ast_passes/ast_validation.rs | 3 ++- src/test/ui/const-generics/argument_order.rs | 7 +++--- .../ui/const-generics/argument_order.stderr | 25 ++----------------- .../const-param-before-other-params.rs | 4 +-- .../const-param-before-other-params.stderr | 8 +----- .../ui/const-generics/defaults/right-order.rs | 11 ++++++++ 6 files changed, 20 insertions(+), 38 deletions(-) create mode 100644 src/test/ui/const-generics/defaults/right-order.rs diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index f4cb400892e7..893de1f60e87 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -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); diff --git a/src/test/ui/const-generics/argument_order.rs b/src/test/ui/const-generics/argument_order.rs index 1d1adf394347..9e071e674e70 100644 --- a/src/test/ui/const-generics/argument_order.rs +++ b/src/test/ui/const-generics/argument_order.rs @@ -1,14 +1,13 @@ #![feature(const_generics)] -//~^ WARN the feature `const_generics` is incomplete +#![allow(incomplete_features)] -struct Bad { //~ ERROR type parameters must be declared prior +struct Bad { arr: [u8; { N }], another: T, } struct AlsoBad { - //~^ 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, } diff --git a/src/test/ui/const-generics/argument_order.stderr b/src/test/ui/const-generics/argument_order.stderr index 19e895b8eb88..058cc346d1b7 100644 --- a/src/test/ui/const-generics/argument_order.stderr +++ b/src/test/ui/const-generics/argument_order.stderr @@ -1,32 +1,11 @@ -error: type parameters must be declared prior to const parameters - --> $DIR/argument_order.rs:4:28 - | -LL | struct Bad { - | -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `` - error: lifetime parameters must be declared prior to const parameters --> $DIR/argument_order.rs:9:32 | LL | struct AlsoBad { | -----------------^^-----^^-------------------- 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 { - | ---------------------^----------------------^- 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 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`. diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index 756e961ce914..0d787d9a67b5 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -5,8 +5,6 @@ fn bar(_: &'a ()) { //~^ ERROR lifetime parameters must be declared prior to const parameters } -fn foo(_: &T) { - //~^ ERROR type parameters must be declared prior to const parameters -} +fn foo(_: &T) {} fn main() {} diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 9b18b8c79edd..5c1171aae605 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -4,11 +4,5 @@ error: lifetime parameters must be declared prior to const parameters LL | fn bar(_: &'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(_: &T) { - | --------------^- help: reorder the parameters: lifetimes, then types, then consts: `` - -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/const-generics/defaults/right-order.rs b/src/test/ui/const-generics/defaults/right-order.rs new file mode 100644 index 000000000000..f1b5c1f02c86 --- /dev/null +++ b/src/test/ui/const-generics/defaults/right-order.rs @@ -0,0 +1,11 @@ +// run-pass +// Verifies that having generic parameters after constants is permitted + +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct A(T); + +fn main() { + let _: A<3> = A(0); +}