about summary refs log tree commit diff
path: root/src/test/ui/const-generics
diff options
context:
space:
mode:
authorBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-01 14:30:16 +0200
committerBastian Kauschke <bastian_kauschke@hotmail.de>2020-09-13 22:53:51 +0200
commite5b82a56c5a9dd5c40f2abe8ee5398fc8acdd4b4 (patch)
tree987e2c50203ad929ef51fd6d4691b6290ff595c6 /src/test/ui/const-generics
parent7402a394471a6738a40fea7d4f1891666e5a80c5 (diff)
downloadrust-e5b82a56c5a9dd5c40f2abe8ee5398fc8acdd4b4.tar.gz
rust-e5b82a56c5a9dd5c40f2abe8ee5398fc8acdd4b4.zip
allow concrete self types in consts
Diffstat (limited to 'src/test/ui/const-generics')
-rw-r--r--src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.rs27
-rw-r--r--src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr24
-rw-r--r--src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.rs21
-rw-r--r--src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr18
4 files changed, 90 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.rs b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.rs
new file mode 100644
index 00000000000..0973b373c12
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.rs
@@ -0,0 +1,27 @@
+#![feature(min_const_generics)]
+
+trait Foo {
+    fn t1() -> [u8; std::mem::size_of::<Self>()]; //~ERROR generic parameters
+}
+
+struct Bar<T>(T);
+
+impl Bar<u8> {
+    fn t2() -> [u8; std::mem::size_of::<Self>()] { todo!() } // ok
+}
+
+impl<T> Bar<T> {
+    fn t3() -> [u8; std::mem::size_of::<Self>()] {} //~ERROR generic `Self`
+}
+
+trait Baz {
+    fn hey();
+}
+
+impl Baz for u16 {
+    fn hey() {
+        let _: [u8; std::mem::size_of::<Self>()]; // ok
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr
new file mode 100644
index 00000000000..94f67735fca
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.stderr
@@ -0,0 +1,24 @@
+error: generic parameters must not be used inside of non trivial constant values
+  --> $DIR/self-ty-in-const-1.rs:4:41
+   |
+LL |     fn t1() -> [u8; std::mem::size_of::<Self>()];
+   |                                         ^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
+   |
+   = help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants
+
+error: generic `Self` types are currently not permitted in anonymous constants
+  --> $DIR/self-ty-in-const-1.rs:14:41
+   |
+LL |     fn t3() -> [u8; std::mem::size_of::<Self>()] {}
+   |                                         ^^^^
+   |
+note: not a concrete type
+  --> $DIR/self-ty-in-const-1.rs:13:1
+   |
+LL | / impl<T> Bar<T> {
+LL | |     fn t3() -> [u8; std::mem::size_of::<Self>()] {}
+LL | | }
+   | |_^
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.rs b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.rs
new file mode 100644
index 00000000000..e7f80d50082
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.rs
@@ -0,0 +1,21 @@
+#![feature(min_const_generics)]
+
+struct Bar<T>(T);
+
+trait Baz {
+    fn hey();
+}
+
+impl Baz for u16 {
+    fn hey() {
+        let _: [u8; std::mem::size_of::<Self>()]; // ok
+    }
+}
+
+impl<T> Baz for Bar<T> {
+    fn hey() {
+        let _: [u8; std::mem::size_of::<Self>()]; //~ERROR generic `Self`
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr
new file mode 100644
index 00000000000..70f44e7de63
--- /dev/null
+++ b/src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.stderr
@@ -0,0 +1,18 @@
+error: generic `Self` types are currently not permitted in anonymous constants
+  --> $DIR/self-ty-in-const-2.rs:17:41
+   |
+LL |         let _: [u8; std::mem::size_of::<Self>()];
+   |                                         ^^^^
+   |
+note: not a concrete type
+  --> $DIR/self-ty-in-const-2.rs:15:1
+   |
+LL | / impl<T> Baz for Bar<T> {
+LL | |     fn hey() {
+LL | |         let _: [u8; std::mem::size_of::<Self>()];
+LL | |     }
+LL | | }
+   | |_^
+
+error: aborting due to previous error
+