about summary refs log tree commit diff
path: root/src/test/ui/const-generics/const_evaluatable_checked
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2021-01-27 13:28:52 +0100
committerBastian Kauschke <bastian_kauschke@hotmail.de>2021-01-27 13:34:45 +0100
commitb519deb224cf94f61599ba0626e2ef3db22826f3 (patch)
tree0079b61e823ddb913b167305b14573f02d41f281 /src/test/ui/const-generics/const_evaluatable_checked
parent742c972c4f92a8f213d05b82ba04797f251f125a (diff)
downloadrust-b519deb224cf94f61599ba0626e2ef3db22826f3.tar.gz
rust-b519deb224cf94f61599ba0626e2ef3db22826f3.zip
const_evaluatable: stop looking into type aliases
Diffstat (limited to 'src/test/ui/const-generics/const_evaluatable_checked')
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr8
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr11
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs6
-rw-r--r--src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs14
4 files changed, 35 insertions, 4 deletions
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr
index c8549f101da..acf0a52ce5b 100644
--- a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr
+++ b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.full.stderr
@@ -1,9 +1,15 @@
 error[E0080]: evaluation of constant value failed
+  --> $DIR/simple_fail.rs:9:48
+   |
+LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
+   |                                                ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
+
+error[E0080]: evaluation of constant value failed
   --> $DIR/simple_fail.rs:6:33
    |
 LL | type Arr<const N: usize> = [u8; N - 1];
    |                                 ^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow
 
-error: aborting due to previous error
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr
index df54b4cbca5..fe5463f8acc 100644
--- a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr
+++ b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr
@@ -7,5 +7,14 @@ LL | type Arr<const N: usize> = [u8; N - 1];
    = help: const parameters may only be used as standalone arguments, i.e. `N`
    = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
 
-error: aborting due to previous error
+error: generic parameters may not be used in const operations
+  --> $DIR/simple_fail.rs:9:48
+   |
+LL | fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
+   |                                                ^ cannot perform const operation using `N`
+   |
+   = help: const parameters may only be used as standalone arguments, i.e. `N`
+   = help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
+
+error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs
index 3cbc077f4f1..c9535d04244 100644
--- a/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs
+++ b/src/test/ui/const-generics/const_evaluatable_checked/simple_fail.rs
@@ -1,12 +1,14 @@
 // revisions: full min
 #![cfg_attr(full, feature(const_generics))]
-#![feature(const_evaluatable_checked)]
+#![cfg_attr(full, feature(const_evaluatable_checked))]
 #![allow(incomplete_features)]
 
 type Arr<const N: usize> = [u8; N - 1]; //[full]~ ERROR evaluation of constant
 //[min]~^ ERROR generic parameters may not be used in const operations
 
-fn test<const N: usize>() -> Arr<N> where Arr<N>: Sized {
+fn test<const N: usize>() -> Arr<N> where [u8; N - 1]: Sized {
+//[min]~^ ERROR generic parameters may not be used in const operations
+//[full]~^^ ERROR evaluation of constant
     todo!()
 }
 
diff --git a/src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs b/src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs
new file mode 100644
index 00000000000..5c768a61be2
--- /dev/null
+++ b/src/test/ui/const-generics/const_evaluatable_checked/ty-alias-substitution.rs
@@ -0,0 +1,14 @@
+// check-pass
+// Test that we correctly substitute generic arguments for type aliases.
+#![feature(const_generics, const_evaluatable_checked)]
+#![allow(incomplete_features)]
+
+type Alias<T, const N: usize> = [T; N + 1];
+
+fn foo<const M: usize>() -> Alias<u32, M>  where [u8; M + 1]: Sized {
+    [0; M + 1]
+}
+
+fn main() {
+    foo::<0>();
+}