diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-04-26 03:50:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-26 03:50:24 +0200 |
| commit | 3a907cee97e9e2b7bc7f5947028e05b3133123ad (patch) | |
| tree | f698c9b5b0ddfe4a55713183bf6086435a1b9dc6 /src/test | |
| parent | 4387f99fc53ca6874c738c8588382adb89f3bbbf (diff) | |
| parent | 6d7c7940b581e8a7f311327e9b48203ce97b8137 (diff) | |
| download | rust-3a907cee97e9e2b7bc7f5947028e05b3133123ad.tar.gz rust-3a907cee97e9e2b7bc7f5947028e05b3133123ad.zip | |
Rollup merge of #60284 - varkor:const-param-of-type-param, r=cramertj
Do not allow const generics to depend on type parameters Fixes https://github.com/rust-lang/rust/issues/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).
Diffstat (limited to 'src/test')
4 files changed, 62 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs new file mode 100644 index 00000000000..af5e8f49754 --- /dev/null +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs @@ -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() {} diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr new file mode 100644 index 00000000000..e3adbcfe602 --- /dev/null +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr @@ -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`. diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs new file mode 100644 index 00000000000..28e0d6c2bb7 --- /dev/null +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.rs @@ -0,0 +1,13 @@ +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +// Currently, const parameters cannot depend on type parameters, because there is no way to +// enforce the `structural_match` property on an arbitrary type parameter. This restriction +// may be relaxed in the future. See https://github.com/rust-lang/rfcs/pull/2000 for more +// details. + +pub struct Dependent<T, const X: T>([(); X]); +//~^ ERROR const parameters cannot depend on type parameters +//~^^ ERROR parameter `T` is never used + +fn main() {} diff --git a/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr b/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr new file mode 100644 index 00000000000..c7dcbe13542 --- /dev/null +++ b/src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr @@ -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:9: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:9: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`. |
