about summary refs log tree commit diff
path: root/tests/ui/cycle-trait
diff options
context:
space:
mode:
authorAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-05 09:13:28 +0100
committerAlbert Larsan <74931857+albertlarsan68@users.noreply.github.com>2023-01-11 09:32:08 +0000
commitcf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch)
tree40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/cycle-trait
parentca855e6e42787ecd062d81d53336fe6788ef51a9 (diff)
downloadrust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz
rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip
Move /src/test to /tests
Diffstat (limited to 'tests/ui/cycle-trait')
-rw-r--r--tests/ui/cycle-trait/cycle-trait-default-type-trait.rs8
-rw-r--r--tests/ui/cycle-trait/cycle-trait-default-type-trait.stderr20
-rw-r--r--tests/ui/cycle-trait/cycle-trait-supertrait-direct.rs7
-rw-r--r--tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr23
-rw-r--r--tests/ui/cycle-trait/cycle-trait-supertrait-indirect.rs13
-rw-r--r--tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr31
6 files changed, 102 insertions, 0 deletions
diff --git a/tests/ui/cycle-trait/cycle-trait-default-type-trait.rs b/tests/ui/cycle-trait/cycle-trait-default-type-trait.rs
new file mode 100644
index 00000000000..6175b7df110
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-default-type-trait.rs
@@ -0,0 +1,8 @@
+// Test a cycle where a type parameter on a trait has a default that
+// again references the trait.
+
+trait Foo<X = Box<dyn Foo>> {
+    //~^ ERROR cycle detected
+}
+
+fn main() { }
diff --git a/tests/ui/cycle-trait/cycle-trait-default-type-trait.stderr b/tests/ui/cycle-trait/cycle-trait-default-type-trait.stderr
new file mode 100644
index 00000000000..9d715f49471
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-default-type-trait.stderr
@@ -0,0 +1,20 @@
+error[E0391]: cycle detected when computing type of `Foo::X`
+  --> $DIR/cycle-trait-default-type-trait.rs:4:23
+   |
+LL | trait Foo<X = Box<dyn Foo>> {
+   |                       ^^^
+   |
+   = note: ...which immediately requires computing type of `Foo::X` again
+note: cycle used when collecting item types in top-level module
+  --> $DIR/cycle-trait-default-type-trait.rs:4:1
+   |
+LL | / trait Foo<X = Box<dyn Foo>> {
+LL | |
+LL | | }
+LL | |
+LL | | fn main() { }
+   | |_____________^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-direct.rs b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.rs
new file mode 100644
index 00000000000..e6ab2c790d6
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.rs
@@ -0,0 +1,7 @@
+// Test a supertrait cycle where a trait extends itself.
+
+trait Chromosome: Chromosome {
+    //~^ ERROR cycle detected
+}
+
+fn main() { }
diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr
new file mode 100644
index 00000000000..f6ffcc4b5aa
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr
@@ -0,0 +1,23 @@
+error[E0391]: cycle detected when computing the super predicates of `Chromosome`
+  --> $DIR/cycle-trait-supertrait-direct.rs:3:1
+   |
+LL | trait Chromosome: Chromosome {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: ...which requires computing the super traits of `Chromosome`...
+  --> $DIR/cycle-trait-supertrait-direct.rs:3:19
+   |
+LL | trait Chromosome: Chromosome {
+   |                   ^^^^^^^^^^
+   = note: ...which again requires computing the super predicates of `Chromosome`, completing the cycle
+note: cycle used when collecting item types in top-level module
+  --> $DIR/cycle-trait-supertrait-direct.rs:3:1
+   |
+LL | / trait Chromosome: Chromosome {
+LL | |
+LL | | }
+   | |_^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.rs b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.rs
new file mode 100644
index 00000000000..9a72b65da88
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.rs
@@ -0,0 +1,13 @@
+// Test a supertrait cycle where the first trait we find (`A`) is not
+// a direct participant in the cycle.
+
+trait A: B {
+}
+
+trait B: C {
+    //~^ ERROR cycle detected
+}
+
+trait C: B { }
+
+fn main() { }
diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr
new file mode 100644
index 00000000000..0a2284e0efb
--- /dev/null
+++ b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr
@@ -0,0 +1,31 @@
+error[E0391]: cycle detected when computing the super predicates of `B`
+  --> $DIR/cycle-trait-supertrait-indirect.rs:7:1
+   |
+LL | trait B: C {
+   | ^^^^^^^^^^
+   |
+note: ...which requires computing the super traits of `B`...
+  --> $DIR/cycle-trait-supertrait-indirect.rs:7:10
+   |
+LL | trait B: C {
+   |          ^
+note: ...which requires computing the super predicates of `C`...
+  --> $DIR/cycle-trait-supertrait-indirect.rs:11:1
+   |
+LL | trait C: B { }
+   | ^^^^^^^^^^
+note: ...which requires computing the super traits of `C`...
+  --> $DIR/cycle-trait-supertrait-indirect.rs:11:10
+   |
+LL | trait C: B { }
+   |          ^
+   = note: ...which again requires computing the super predicates of `B`, completing the cycle
+note: cycle used when computing the super traits of `A`
+  --> $DIR/cycle-trait-supertrait-indirect.rs:4:10
+   |
+LL | trait A: B {
+   |          ^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.