diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-08-05 18:59:53 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-08-06 22:37:20 +0200 |
| commit | 37c29adabc638f9c601daf5b78d0f6de63e35f99 (patch) | |
| tree | 7a1f4d8a1bc4f28d8d67842efbb35081d104dc84 /src/test | |
| parent | 0d54f571c10dbc7e6d8632698c5f08f77b4a7578 (diff) | |
| download | rust-37c29adabc638f9c601daf5b78d0f6de63e35f99.tar.gz rust-37c29adabc638f9c601daf5b78d0f6de63e35f99.zip | |
allow complex expressions in assoc consts
Diffstat (limited to 'src/test')
3 files changed, 19 insertions, 17 deletions
diff --git a/src/test/ui/const-generics/min_const_generics/assoc_const.rs b/src/test/ui/const-generics/min_const_generics/assoc_const.rs new file mode 100644 index 00000000000..fa75613d9dd --- /dev/null +++ b/src/test/ui/const-generics/min_const_generics/assoc_const.rs @@ -0,0 +1,18 @@ +// check-pass +#![feature(min_const_generics)] + +struct Foo<const N: usize>; + +impl<const N: usize> Foo<N> { + const VALUE: usize = N * 2; +} + +trait Bar { + const ASSOC: usize; +} + +impl<const N: usize> Bar for Foo<N> { + const ASSOC: usize = N * 3; +} + +fn main() {} diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.rs b/src/test/ui/const-generics/min_const_generics/complex-expression.rs index 201af9fcef3..f9cb0d2829d 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-expression.rs +++ b/src/test/ui/const-generics/min_const_generics/complex-expression.rs @@ -26,12 +26,4 @@ trait Foo { const ASSOC: usize; } -impl<const N: usize> Foo for [u8; N] { - const ASSOC: usize = N + 1; - //~^ ERROR generic parameters must not be used inside of non trivial constant values - // FIXME(min_const_generics): We probably have to allow this as we can - // already allow referencing type parameters here on stable. -} - - fn main() {} diff --git a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr index 03857aee076..baed8d13f00 100644 --- a/src/test/ui/const-generics/min_const_generics/complex-expression.stderr +++ b/src/test/ui/const-generics/min_const_generics/complex-expression.stderr @@ -30,13 +30,5 @@ LL | let _ = [0; N + 1]; | = help: it is currently only allowed to use either `N` or `{ N }` as generic constants -error: generic parameters must not be used inside of non trivial constant values - --> $DIR/complex-expression.rs:30:26 - | -LL | const ASSOC: usize = N + 1; - | ^ non-trivial anonymous constants must not depend on the parameter `N` - | - = help: it is currently only allowed to use either `N` or `{ N }` as generic constants - -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors |
