forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#60284 - varkor:const-param-of-type-param, r…
…=cramertj Do not allow const generics to depend on type parameters Fixes rust-lang#60264. In https://github.com/rust-lang/rust/pull/58191/files/b534cf992d0189032207f395c27ed092c89b40c7#diff-aeb0880081a991f34aef2ab889e1fb7a, it was suggested that there might be a better place for this error, but as this bug already affects stable, it's probably worth merging this now, and refactoring afterwards (I can open an issue for this).
- Loading branch information
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use std::marker::PhantomData; | ||
|
||
struct B<T, const N: T>(PhantomData<[T; N]>); //~ ERROR const generics are unstable | ||
//~^ ERROR const parameters cannot depend on type parameters | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
error[E0671]: const parameters cannot depend on type parameters | ||
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22 | ||
| | ||
LL | struct B<T, const N: T>(PhantomData<[T; N]>); | ||
| ^ const parameter depends on type parameter | ||
|
||
error[E0658]: const generics are unstable | ||
--> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:19 | ||
| | ||
LL | struct B<T, const N: T>(PhantomData<[T; N]>); | ||
| ^ | ||
| | ||
= note: for more information, see https://github.com/rust-lang/rust/issues/44580 | ||
= help: add #![feature(const_generics)] to the crate attributes to enable | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0658, E0671. | ||
For more information about an error, try `rustc --explain E0658`. |
7 changes: 7 additions & 0 deletions
7
src/test/ui/const-generics/const-param-type-depends-on-type-param.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
pub struct Dependent<T, const X: T>([(); X]); //~ ERROR const parameters | ||
//~^ ERROR parameter `T` is never used | ||
|
||
fn main() {} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/const-param-type-depends-on-type-param.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error[E0671]: const parameters cannot depend on type parameters | ||
--> $DIR/const-param-type-depends-on-type-param.rs:4:34 | ||
| | ||
LL | pub struct Dependent<T, const X: T>([(); X]); | ||
| ^ const parameter depends on type parameter | ||
|
||
error[E0392]: parameter `T` is never used | ||
--> $DIR/const-param-type-depends-on-type-param.rs:4:22 | ||
| | ||
LL | pub struct Dependent<T, const X: T>([(); X]); | ||
| ^ unused parameter | ||
| | ||
= help: consider removing `T` or using a marker such as `std::marker::PhantomData` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0392, E0671. | ||
For more information about an error, try `rustc --explain E0392`. |