about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_ast_passes/ast_validation.rs7
-rw-r--r--src/test/ui/const-generics/defaults/intermixed-lifetime.rs9
-rw-r--r--src/test/ui/const-generics/defaults/intermixed-lifetime.stderr8
-rw-r--r--src/test/ui/const-generics/defaults/needs-feature.rs8
-rw-r--r--src/test/ui/const-generics/defaults/needs-feature.stderr18
-rw-r--r--src/test/ui/const-generics/defaults/right-order.rs2
-rw-r--r--src/test/ui/const-generics/defaults/type-after-const-requires-default.rs10
7 files changed, 59 insertions, 3 deletions
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs
index 893de1f60e8..4ebf089c68b 100644
--- a/src/librustc_ast_passes/ast_validation.rs
+++ b/src/librustc_ast_passes/ast_validation.rs
@@ -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);
diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs
new file mode 100644
index 00000000000..ff052edcec7
--- /dev/null
+++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs
@@ -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() {}
diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr
new file mode 100644
index 00000000000..0880581ec7f
--- /dev/null
+++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr
@@ -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
+
diff --git a/src/test/ui/const-generics/defaults/needs-feature.rs b/src/test/ui/const-generics/defaults/needs-feature.rs
new file mode 100644
index 00000000000..ea38a4022ae
--- /dev/null
+++ b/src/test/ui/const-generics/defaults/needs-feature.rs
@@ -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() {}
diff --git a/src/test/ui/const-generics/defaults/needs-feature.stderr b/src/test/ui/const-generics/defaults/needs-feature.stderr
new file mode 100644
index 00000000000..30604feab1b
--- /dev/null
+++ b/src/test/ui/const-generics/defaults/needs-feature.stderr
@@ -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`.
diff --git a/src/test/ui/const-generics/defaults/right-order.rs b/src/test/ui/const-generics/defaults/right-order.rs
index f1b5c1f02c8..fce3ab2e6a3 100644
--- a/src/test/ui/const-generics/defaults/right-order.rs
+++ b/src/test/ui/const-generics/defaults/right-order.rs
@@ -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)]
diff --git a/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs b/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs
new file mode 100644
index 00000000000..fc977d6617c
--- /dev/null
+++ b/src/test/ui/const-generics/defaults/type-after-const-requires-default.rs
@@ -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() {}