-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Remove restriction on type parameters preceding consts w/ feature const-generics #74953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
58b1a04
18481cb
f858828
b8352eb
319c4f4
1ae1a63
4f461f5
be0d6f1
64f6437
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -775,13 +775,13 @@ fn validate_generic_param_order<'a>( | |
err.span_suggestion( | ||
span, | ||
&format!( | ||
"reorder the parameters: lifetimes, then types{}", | ||
if sess.features_untracked().const_generics | ||
|| sess.features_untracked().min_const_generics | ||
{ | ||
", then consts" | ||
"reorder the parameters: lifetimes{}", | ||
if sess.features_untracked().const_generics { | ||
", then consts and types" | ||
} else if sess.features_untracked().min_const_generics { | ||
", then consts, then types" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ups There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JulianKnodt do you want to open a PR for this? Otherwise I will quickly fix that |
||
} else { | ||
"" | ||
", then types" | ||
}, | ||
), | ||
ordered_params.clone(), | ||
|
@@ -1158,7 +1158,11 @@ impl<'a> Visitor<'a> for AstValidator<'a> { | |
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident), | ||
GenericParamKind::Const { ref ty, kw_span: _ } => { | ||
let ty = pprust::ty_to_string(ty); | ||
(ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty))) | ||
let unordered = self.session.features_untracked().const_generics; | ||
( | ||
ParamKindOrd::Const { unordered }, | ||
Some(format!("const {}: {}", param.ident, ty)), | ||
) | ||
} | ||
}; | ||
(kind, Some(&*param.bounds), param.ident.span, ident) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
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 | ||
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>` | ||
|
||
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>; | ||
| ^^^^^^^ | ||
| | ||
= note: lifetime arguments must be provided before type arguments | ||
= help: reorder the arguments: lifetimes, then types, then consts: `<'a, 'b, T, U, N, M>` | ||
= help: reorder the arguments: lifetimes, then consts: `<'a, 'b, N, T, M, U>` | ||
|
||
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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/const-arg-type-arg-misordered.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]: constant provided when a type was expected | ||
--> $DIR/const-arg-type-arg-misordered.rs:6:35 | ||
| | ||
LL | fn foo<const N: usize>() -> Array<N, ()> { | ||
| ^ | ||
| | ||
= note: type arguments must be provided before constant arguments | ||
= help: reorder the arguments: types, then consts: `<T, N>` | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0747`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// run-pass | ||
// Checks a complicated usage of unordered params | ||
|
||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
#![allow(dead_code)] | ||
|
||
struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> { | ||
args: &'a [&'a [T; M]; N], | ||
specifier: A, | ||
} | ||
|
||
fn main() { | ||
let array = [1, 2, 3]; | ||
let nest = [&array]; | ||
let _ = NestedArrays { | ||
args: &nest, | ||
specifier: true, | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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 | ||
|
||
struct Bar<const N: usize, T = u32, 'a>(&'a (), T); | ||
//~^ Error lifetime parameters must be declared prior to type parameters | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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 consts and types: `<'a, const N: usize, T>` | ||
|
||
error: lifetime parameters must be declared prior to type parameters | ||
--> $DIR/intermixed-lifetime.rs:9:37 | ||
| | ||
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T); | ||
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T>` | ||
|
||
error: aborting due to 2 previous errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: type parameters must be declared prior to const parameters | ||
--> $DIR/needs-feature.rs:10:26 | ||
| | ||
LL | struct A<const N: usize, T=u32>(T); | ||
| -----------------^----- help: reorder the parameters: lifetimes, then consts, then types: `<T, const N: usize>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error message is wrong. |
||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error: type parameters must be declared prior to const parameters | ||
--> $DIR/needs-feature.rs:10: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:10:16 | ||
| | ||
LL | struct A<const N: usize, T=u32>(T); | ||
| ^ | ||
| | ||
= note: see issue #74878 <https://github.com/rust-lang/rust/issues/74878> for more information | ||
= help: add `#![feature(min_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`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//[full] run-pass | ||
// Verifies that having generic parameters after constants is not permitted without the | ||
// `const_generics` feature. | ||
// revisions: none min full | ||
|
||
#![cfg_attr(full, feature(const_generics))] | ||
#![cfg_attr(full, allow(incomplete_features))] | ||
#![cfg_attr(min, feature(min_const_generics))] | ||
|
||
struct A<const N: usize, T=u32>(T); | ||
//[none]~^ ERROR type parameters must be declared prior | ||
//[none]~| ERROR const generics are unstable | ||
//[min]~^^^ ERROR type parameters must be declared prior | ||
|
||
fn main() { | ||
let _: A<3> = A(0); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// run-pass | ||
// Checks some basic test cases for defaults. | ||
#![feature(const_generics)] | ||
#![allow(incomplete_features)] | ||
#![allow(dead_code)] | ||
|
||
struct FixedOutput<'a, const N: usize, T=u32> { | ||
out: &'a [T; N], | ||
} | ||
|
||
trait FixedOutputter { | ||
fn out(&self) -> FixedOutput<'_, 10>; | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
Uh oh!
There was an error while loading. Please reload this page.