summaryrefslogtreecommitdiffstats
path: root/src/test/ui/cycle-trait
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/cycle-trait')
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs9
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr39
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-supertrait-direct.rs7
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-supertrait-direct.stderr23
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.rs13
-rw-r--r--src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr31
6 files changed, 122 insertions, 0 deletions
diff --git a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs
new file mode 100644
index 000000000..b2edc1a1f
--- /dev/null
+++ b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.rs
@@ -0,0 +1,9 @@
+// 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
+ //~| ERROR cycle detected
+}
+
+fn main() { }
diff --git a/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr
new file mode 100644
index 000000000..d4976a0f9
--- /dev/null
+++ b/src/test/ui/cycle-trait/cycle-trait-default-type-trait.stderr
@@ -0,0 +1,39 @@
+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 | |
+LL | | fn main() { }
+ | |_____________^
+
+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 | |
+LL | | fn main() { }
+ | |_____________^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/cycle-trait/cycle-trait-supertrait-direct.rs b/src/test/ui/cycle-trait/cycle-trait-supertrait-direct.rs
new file mode 100644
index 000000000..e6ab2c790
--- /dev/null
+++ b/src/test/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/src/test/ui/cycle-trait/cycle-trait-supertrait-direct.stderr b/src/test/ui/cycle-trait/cycle-trait-supertrait-direct.stderr
new file mode 100644
index 000000000..f6ffcc4b5
--- /dev/null
+++ b/src/test/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/src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.rs b/src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.rs
new file mode 100644
index 000000000..9a72b65da
--- /dev/null
+++ b/src/test/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/src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr b/src/test/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr
new file mode 100644
index 000000000..0a2284e0e
--- /dev/null
+++ b/src/test/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`.