about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkadmin <julianknodt@gmail.com>2020-07-30 18:39:53 +0000
committerkadmin <julianknodt@gmail.com>2020-08-08 04:40:07 +0000
commit18481cbec981f320abfb83df0e96fd127def7cd5 (patch)
tree1dbec3e83e917272f143fe729d6ee6befee44792
parent58b1a04b9edc19a2f44f780475ebace12a0ab435 (diff)
downloadrust-18481cbec981f320abfb83df0e96fd127def7cd5.tar.gz
rust-18481cbec981f320abfb83df0e96fd127def7cd5.zip
Rm restriction on ord of default types w/ consts
-rw-r--r--src/librustc_ast_passes/ast_validation.rs3
-rw-r--r--src/test/ui/const-generics/argument_order.rs7
-rw-r--r--src/test/ui/const-generics/argument_order.stderr25
-rw-r--r--src/test/ui/const-generics/const-param-before-other-params.rs4
-rw-r--r--src/test/ui/const-generics/const-param-before-other-params.stderr8
-rw-r--r--src/test/ui/const-generics/defaults/right-order.rs11
6 files changed, 20 insertions, 38 deletions
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs
index f4cb400892e..893de1f60e8 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 1d1adf39434..9e071e674e7 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<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,
 }
diff --git a/src/test/ui/const-generics/argument_order.stderr b/src/test/ui/const-generics/argument_order.stderr
index 19e895b8eb8..058cc346d1b 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<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`.
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 756e961ce91..0d787d9a67b 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<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() {}
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 9b18b8c79ed..5c1171aae60 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<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
 
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 00000000000..f1b5c1f02c8
--- /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<const N: usize, T=u32>(T);
+
+fn main() {
+  let _: A<3> = A(0);
+}