about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2022-01-29 01:49:15 +1100
committerDeadbeef <ent3rm4n@gmail.com>2022-07-23 14:25:56 +0000
commit05bb26fdb6635508aaa75c26e593672a86d03084 (patch)
treef4246b6fc8c3e8989e57f31c3e1cbfc8f11ea7fc /src/test
parent08cb87843010ef1dcee0e8bc91c3d95eed70c1eb (diff)
downloadrust-05bb26fdb6635508aaa75c26e593672a86d03084.tar.gz
rust-05bb26fdb6635508aaa75c26e593672a86d03084.zip
Add tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs14
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr24
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs16
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr24
-rw-r--r--src/test/ui/rfc-2632-const-trait-impl/super-traits.rs22
5 files changed, 100 insertions, 0 deletions
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
new file mode 100644
index 00000000000..7b38c15afc2
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.rs
@@ -0,0 +1,14 @@
+#![feature(const_trait_impl)]
+
+trait Foo {
+    fn a(&self);
+}
+trait Bar: ~const Foo {}
+
+const fn foo<T: Bar>(x: &T) {
+    x.a();
+    //~^ ERROR the trait bound
+    //~| ERROR cannot call
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr
new file mode 100644
index 00000000000..1766cdbee8a
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail-2.stderr
@@ -0,0 +1,24 @@
+error[E0277]: the trait bound `T: ~const Foo` is not satisfied
+  --> $DIR/super-traits-fail-2.rs:9:7
+   |
+LL |     x.a();
+   |       ^^^ the trait `~const Foo` is not implemented for `T`
+   |
+note: the trait `Foo` is implemented for `T`, but that implementation is not `const`
+  --> $DIR/super-traits-fail-2.rs:9:7
+   |
+LL |     x.a();
+   |       ^^^
+
+error[E0015]: cannot call non-const fn `<T as Foo>::a` in constant functions
+  --> $DIR/super-traits-fail-2.rs:9:7
+   |
+LL |     x.a();
+   |       ^^^
+   |
+   = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0015, E0277.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
new file mode 100644
index 00000000000..af465cad3d2
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.rs
@@ -0,0 +1,16 @@
+#![feature(const_trait_impl)]
+
+trait Foo {
+    fn a(&self);
+}
+trait Bar: ~const Foo {}
+
+struct S;
+impl Foo for S {
+    fn a(&self) {}
+}
+
+impl const Bar for S {}
+//~^ ERROR the trait bound
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
new file mode 100644
index 00000000000..9e8b8f8c6ba
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits-fail.stderr
@@ -0,0 +1,24 @@
+error[E0277]: the trait bound `S: ~const Foo` is not satisfied
+  --> $DIR/super-traits-fail.rs:13:12
+   |
+LL | impl const Bar for S {}
+   |            ^^^ the trait `~const Foo` is not implemented for `S`
+   |
+note: the trait `Foo` is implemented for `S`, but that implementation is not `const`
+  --> $DIR/super-traits-fail.rs:13:12
+   |
+LL | impl const Bar for S {}
+   |            ^^^
+note: required by a bound in `Bar`
+  --> $DIR/super-traits-fail.rs:6:12
+   |
+LL | trait Bar: ~const Foo {}
+   |            ^^^^^^^^^^ required by this bound in `Bar`
+help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
+   |
+LL | impl const Bar for S where S: ~const Foo {}
+   |                      +++++++++++++++++++
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
new file mode 100644
index 00000000000..aded4ca9a99
--- /dev/null
+++ b/src/test/ui/rfc-2632-const-trait-impl/super-traits.rs
@@ -0,0 +1,22 @@
+// check-pass
+#![feature(const_trait_impl)]
+
+trait Foo {
+    fn a(&self);
+}
+trait Bar: ~const Foo {}
+
+struct S;
+impl const Foo for S {
+    fn a(&self) {}
+}
+
+impl const Bar for S {}
+
+const fn foo<T: ~const Bar>(t: &T) {
+    t.a();
+}
+
+const _: () = foo(&S);
+
+fn main() {}