Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f858828

Browse files
committed
Added +1 test for only works w/ feat const gen
Added this test to ensure that reordering the parameters only works with the feature const generics enabled. Fixed nits Also added another test to verify that intermixed lifetimes are forbidden
1 parent 18481cb commit f858828

File tree

7 files changed

+59
-3
lines changed

7 files changed

+59
-3
lines changed

src/librustc_ast_passes/ast_validation.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,11 @@ fn validate_generic_param_order<'a>(
735735
}
736736
let max_param = &mut max_param;
737737
match max_param {
738-
Some(ParamKindOrd::Const) if ParamKindOrd::Type == kind &&
739-
sess.features_untracked().const_generics => (),
738+
Some(ParamKindOrd::Const)
739+
if ParamKindOrd::Type == kind && sess.features_untracked().const_generics =>
740+
{
741+
()
742+
}
740743
Some(max_param) if *max_param > kind => {
741744
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
742745
entry.1.push(span);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Checks that lifetimes cannot be interspersed between consts and types.
2+
3+
#![feature(const_generics)]
4+
#![allow(incomplete_features)]
5+
6+
struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
7+
//~^ Error lifetime parameters must be declared prior to const parameters
8+
9+
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: lifetime parameters must be declared prior to const parameters
2+
--> $DIR/intermixed-lifetime.rs:6:28
3+
|
4+
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
5+
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
6+
7+
error: aborting due to previous error
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Verifies that having generic parameters after constants is not permitted without the
2+
// `const_generics` feature.
3+
4+
struct A<const N: usize, T=u32>(T);
5+
//~^ ERROR type parameters must be declared prior
6+
//~| ERROR const generics are unstable
7+
8+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: type parameters must be declared prior to const parameters
2+
--> $DIR/needs-feature.rs:4:26
3+
|
4+
LL | struct A<const N: usize, T=u32>(T);
5+
| -----------------^----- help: reorder the parameters: lifetimes, then types: `<T, const N: usize>`
6+
7+
error[E0658]: const generics are unstable
8+
--> $DIR/needs-feature.rs:4:16
9+
|
10+
LL | struct A<const N: usize, T=u32>(T);
11+
| ^
12+
|
13+
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
14+
= help: add `#![feature(const_generics)]` to the crate attributes to enable
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.

src/test/ui/const-generics/defaults/right-order.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-pass
2-
// Verifies that having generic parameters after constants is permitted
2+
// Verifies that having generic parameters after constants is permitted.
33

44
#![feature(const_generics)]
55
#![allow(incomplete_features)]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-pass
2+
// Verifies that having generic parameters after constants is permitted
3+
4+
#![feature(const_generics)]
5+
#![allow(incomplete_features)]
6+
7+
#[allow(dead_code)]
8+
struct A<const N: usize, T>(T);
9+
10+
fn main() {}

0 commit comments

Comments
 (0)