diff options
| author | Caio <c410.f3r@gmail.com> | 2021-11-06 15:35:20 -0300 |
|---|---|---|
| committer | Caio <c410.f3r@gmail.com> | 2021-11-06 15:35:20 -0300 |
| commit | 7fd15f09008dd72f40d76a5bebb60e3991095a5f (patch) | |
| tree | 45b540395fe976fa12c67d74f4f965023b84ad3f /src/test/ui/const-generics | |
| parent | d32993afe81a49701edd6f2b8f018020ca50da1a (diff) | |
| download | rust-7fd15f09008dd72f40d76a5bebb60e3991095a5f.tar.gz rust-7fd15f09008dd72f40d76a5bebb60e3991095a5f.zip | |
Move some tests to more reasonable directories
Diffstat (limited to 'src/test/ui/const-generics')
4 files changed, 60 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/auxiliary/legacy-const-generics.rs b/src/test/ui/const-generics/auxiliary/legacy-const-generics.rs new file mode 100644 index 00000000000..67352a2fbbb --- /dev/null +++ b/src/test/ui/const-generics/auxiliary/legacy-const-generics.rs @@ -0,0 +1,6 @@ +#![feature(rustc_attrs)] + +#[rustc_legacy_const_generics(1)] +pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] { + [x, Y, z] +} diff --git a/src/test/ui/const-generics/legacy-const-generics-bad.rs b/src/test/ui/const-generics/legacy-const-generics-bad.rs new file mode 100644 index 00000000000..538eee337cc --- /dev/null +++ b/src/test/ui/const-generics/legacy-const-generics-bad.rs @@ -0,0 +1,16 @@ +// aux-build:legacy-const-generics.rs + +extern crate legacy_const_generics; + +fn foo<const N: usize>() { + let a = 1; + legacy_const_generics::foo(0, a, 2); + //~^ ERROR attempt to use a non-constant value in a constant + + legacy_const_generics::foo(0, N, 2); + + legacy_const_generics::foo(0, N + 1, 2); + //~^ ERROR generic parameters may not be used in const operations +} + +fn main() {} diff --git a/src/test/ui/const-generics/legacy-const-generics-bad.stderr b/src/test/ui/const-generics/legacy-const-generics-bad.stderr new file mode 100644 index 00000000000..3c78dd6c780 --- /dev/null +++ b/src/test/ui/const-generics/legacy-const-generics-bad.stderr @@ -0,0 +1,20 @@ +error[E0435]: attempt to use a non-constant value in a constant + --> $DIR/legacy-const-generics-bad.rs:7:35 + | +LL | let a = 1; + | ----- help: consider using `const` instead of `let`: `const a` +LL | legacy_const_generics::foo(0, a, 2); + | ^ non-constant value + +error: generic parameters may not be used in const operations + --> $DIR/legacy-const-generics-bad.rs:12:35 + | +LL | legacy_const_generics::foo(0, N + 1, 2); + | ^ cannot perform const operation using `N` + | + = help: const parameters may only be used as standalone arguments, i.e. `N` + = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0435`. diff --git a/src/test/ui/const-generics/legacy-const-generics.rs b/src/test/ui/const-generics/legacy-const-generics.rs new file mode 100644 index 00000000000..9abc72d98e6 --- /dev/null +++ b/src/test/ui/const-generics/legacy-const-generics.rs @@ -0,0 +1,18 @@ +// aux-build:legacy-const-generics.rs +// run-pass + +#![feature(rustc_attrs)] + +extern crate legacy_const_generics; + +#[rustc_legacy_const_generics(1)] +pub fn bar<const Y: usize>(x: usize, z: usize) -> [usize; 3] { + [x, Y, z] +} + +fn main() { + assert_eq!(legacy_const_generics::foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]); + assert_eq!(legacy_const_generics::foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]); + // FIXME: Only works cross-crate + //assert_eq!(bar(0, 1, 2), [0, 1, 2]); +} |
