diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 893de1f60e87..4ebf089c68bd 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 000000000000..ff052edcec7c --- /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(&'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 000000000000..0880581ec7f0 --- /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(&'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 000000000000..ea38a4022ae0 --- /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(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 000000000000..30604feab1b9 --- /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(T); + | -----------------^----- help: reorder the parameters: lifetimes, then types: `` + +error[E0658]: const generics are unstable + --> $DIR/needs-feature.rs:4:16 + | +LL | struct A(T); + | ^ + | + = note: see issue #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 f1b5c1f02c86..fce3ab2e6a3a 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 000000000000..fc977d6617c5 --- /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(T); + +fn main() {}