Skip to content

Commit 18481cb

Browse files
committed
Rm restriction on ord of default types w/ consts
1 parent 58b1a04 commit 18481cb

File tree

6 files changed

+20
-38
lines changed

6 files changed

+20
-38
lines changed

src/librustc_ast_passes/ast_validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,8 @@ 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 => (),
738+
Some(ParamKindOrd::Const) if ParamKindOrd::Type == kind &&
739+
sess.features_untracked().const_generics => (),
739740
Some(max_param) if *max_param > kind => {
740741
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
741742
entry.1.push(span);

src/test/ui/const-generics/argument_order.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
2+
#![allow(incomplete_features)]
33

4-
struct Bad<const N: usize, T> { //~ ERROR type parameters must be declared prior
4+
struct Bad<const N: usize, T> {
55
arr: [u8; { N }],
66
another: T,
77
}
88

99
struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
10-
//~^ ERROR type parameters must be declared prior
11-
//~| ERROR lifetime parameters must be declared prior
10+
//~^ ERROR lifetime parameters must be declared prior
1211
a: &'a T,
1312
b: &'b U,
1413
}
Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
1-
error: type parameters must be declared prior to const parameters
2-
--> $DIR/argument_order.rs:4:28
3-
|
4-
LL | struct Bad<const N: usize, T> {
5-
| -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>`
6-
71
error: lifetime parameters must be declared prior to const parameters
82
--> $DIR/argument_order.rs:9:32
93
|
104
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
115
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
126

13-
error: type parameters must be declared prior to const parameters
14-
--> $DIR/argument_order.rs:9:36
15-
|
16-
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
17-
| ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
18-
19-
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
20-
--> $DIR/argument_order.rs:1:12
21-
|
22-
LL | #![feature(const_generics)]
23-
| ^^^^^^^^^^^^^^
24-
|
25-
= note: `#[warn(incomplete_features)]` on by default
26-
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
27-
287
error[E0747]: lifetime provided when a type was expected
29-
--> $DIR/argument_order.rs:17:23
8+
--> $DIR/argument_order.rs:16:23
309
|
3110
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
3211
| ^^^^^^^
3312
|
3413
= note: lifetime arguments must be provided before type arguments
3514
= help: reorder the arguments: lifetimes, then types, then consts: `<'a, 'b, T, U, N, M>`
3615

37-
error: aborting due to 4 previous errors; 1 warning emitted
16+
error: aborting due to 2 previous errors
3817

3918
For more information about this error, try `rustc --explain E0747`.

src/test/ui/const-generics/const-param-before-other-params.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ fn bar<const X: (), 'a>(_: &'a ()) {
55
//~^ ERROR lifetime parameters must be declared prior to const parameters
66
}
77

8-
fn foo<const X: (), T>(_: &T) {
9-
//~^ ERROR type parameters must be declared prior to const parameters
10-
}
8+
fn foo<const X: (), T>(_: &T) {}
119

1210
fn main() {}

src/test/ui/const-generics/const-param-before-other-params.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,5 @@ error: lifetime parameters must be declared prior to const parameters
44
LL | fn bar<const X: (), 'a>(_: &'a ()) {
55
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
66

7-
error: type parameters must be declared prior to const parameters
8-
--> $DIR/const-param-before-other-params.rs:8:21
9-
|
10-
LL | fn foo<const X: (), T>(_: &T) {
11-
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
12-
13-
error: aborting due to 2 previous errors
7+
error: aborting due to previous error
148

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

0 commit comments

Comments
 (0)