summaryrefslogtreecommitdiffstats
path: root/src/test/ui/infinite
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/test/ui/infinite/infinite-autoderef.rs26
-rw-r--r--src/test/ui/infinite/infinite-autoderef.stderr54
-rw-r--r--src/test/ui/infinite/infinite-instantiation.polonius.stderr15
-rw-r--r--src/test/ui/infinite/infinite-instantiation.rs29
-rw-r--r--src/test/ui/infinite/infinite-instantiation.stderr15
-rw-r--r--src/test/ui/infinite/infinite-macro-expansion.rs7
-rw-r--r--src/test/ui/infinite/infinite-macro-expansion.stderr14
-rw-r--r--src/test/ui/infinite/infinite-recursion-const-fn.rs11
-rw-r--r--src/test/ui/infinite/infinite-recursion-const-fn.stderr145
-rw-r--r--src/test/ui/infinite/infinite-struct.rs9
-rw-r--r--src/test/ui/infinite/infinite-struct.stderr16
-rw-r--r--src/test/ui/infinite/infinite-tag-type-recursion.rs4
-rw-r--r--src/test/ui/infinite/infinite-tag-type-recursion.stderr16
-rw-r--r--src/test/ui/infinite/infinite-trait-alias-recursion.rs10
-rw-r--r--src/test/ui/infinite/infinite-trait-alias-recursion.stderr42
-rw-r--r--src/test/ui/infinite/infinite-type-alias-mutual-recursion.rs6
-rw-r--r--src/test/ui/infinite/infinite-type-alias-mutual-recursion.stderr34
-rw-r--r--src/test/ui/infinite/infinite-vec-type-recursion.rs4
-rw-r--r--src/test/ui/infinite/infinite-vec-type-recursion.stderr22
19 files changed, 479 insertions, 0 deletions
diff --git a/src/test/ui/infinite/infinite-autoderef.rs b/src/test/ui/infinite/infinite-autoderef.rs
new file mode 100644
index 000000000..cbbe1f81d
--- /dev/null
+++ b/src/test/ui/infinite/infinite-autoderef.rs
@@ -0,0 +1,26 @@
+// error-pattern: reached the recursion limit while auto-dereferencing
+// compile-flags: -Zdeduplicate-diagnostics=yes
+
+use std::ops::Deref;
+
+struct Foo;
+
+impl Deref for Foo {
+ type Target = Foo;
+
+ fn deref(&self) -> &Foo {
+ self
+ }
+}
+
+pub fn main() {
+ let mut x;
+ loop {
+ x = Box::new(x);
+ x.foo;
+ x.bar();
+ }
+
+ Foo.foo;
+ Foo.bar();
+}
diff --git a/src/test/ui/infinite/infinite-autoderef.stderr b/src/test/ui/infinite/infinite-autoderef.stderr
new file mode 100644
index 000000000..51b61e3a6
--- /dev/null
+++ b/src/test/ui/infinite/infinite-autoderef.stderr
@@ -0,0 +1,54 @@
+error[E0308]: mismatched types
+ --> $DIR/infinite-autoderef.rs:19:13
+ |
+LL | x = Box::new(x);
+ | ^^^^^^^^^^^ cyclic type of infinite size
+ |
+help: consider unboxing the value
+ |
+LL | x = *Box::new(x);
+ | +
+
+error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
+ --> $DIR/infinite-autoderef.rs:24:5
+ |
+LL | Foo.foo;
+ | ^^^^^^^ deref recursion limit reached
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
+
+error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
+ --> $DIR/infinite-autoderef.rs:24:9
+ |
+LL | Foo.foo;
+ | ^^^ deref recursion limit reached
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
+
+error[E0609]: no field `foo` on type `Foo`
+ --> $DIR/infinite-autoderef.rs:24:9
+ |
+LL | Foo.foo;
+ | ^^^ unknown field
+
+error[E0055]: reached the recursion limit while auto-dereferencing `Foo`
+ --> $DIR/infinite-autoderef.rs:25:9
+ |
+LL | Foo.bar();
+ | ^^^ deref recursion limit reached
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_autoderef`)
+
+error[E0599]: no method named `bar` found for struct `Foo` in the current scope
+ --> $DIR/infinite-autoderef.rs:25:9
+ |
+LL | struct Foo;
+ | ---------- method `bar` not found for this struct
+...
+LL | Foo.bar();
+ | ^^^ method not found in `Foo`
+
+error: aborting due to 6 previous errors
+
+Some errors have detailed explanations: E0055, E0308, E0599, E0609.
+For more information about an error, try `rustc --explain E0055`.
diff --git a/src/test/ui/infinite/infinite-instantiation.polonius.stderr b/src/test/ui/infinite/infinite-instantiation.polonius.stderr
new file mode 100644
index 000000000..29eb8c481
--- /dev/null
+++ b/src/test/ui/infinite/infinite-instantiation.polonius.stderr
@@ -0,0 +1,15 @@
+error: reached the recursion limit while instantiating `function::<Option<Option<Option<...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
+ --> $DIR/infinite-instantiation.rs:22:9
+ |
+LL | function(counter - 1, t.to_option());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `function` defined here
+ --> $DIR/infinite-instantiation.rs:20:1
+ |
+LL | fn function<T:ToOpt + Clone>(counter: usize, t: T) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: the full type name has been written to '$TEST_BUILD_DIR/infinite/infinite-instantiation.polonius/infinite-instantiation.long-type.txt'
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/infinite/infinite-instantiation.rs b/src/test/ui/infinite/infinite-instantiation.rs
new file mode 100644
index 000000000..9b9f332ca
--- /dev/null
+++ b/src/test/ui/infinite/infinite-instantiation.rs
@@ -0,0 +1,29 @@
+// build-fail
+// normalize-stderr-test: ".nll/" -> "/"
+
+trait ToOpt: Sized {
+ fn to_option(&self) -> Option<Self>;
+}
+
+impl ToOpt for usize {
+ fn to_option(&self) -> Option<usize> {
+ Some(*self)
+ }
+}
+
+impl<T:Clone> ToOpt for Option<T> {
+ fn to_option(&self) -> Option<Option<T>> {
+ Some((*self).clone())
+ }
+}
+
+fn function<T:ToOpt + Clone>(counter: usize, t: T) {
+ if counter > 0 {
+ function(counter - 1, t.to_option());
+ //~^ ERROR reached the recursion limit while instantiating `function::<Option<
+ }
+}
+
+fn main() {
+ function(22, 22);
+}
diff --git a/src/test/ui/infinite/infinite-instantiation.stderr b/src/test/ui/infinite/infinite-instantiation.stderr
new file mode 100644
index 000000000..52f578134
--- /dev/null
+++ b/src/test/ui/infinite/infinite-instantiation.stderr
@@ -0,0 +1,15 @@
+error: reached the recursion limit while instantiating `function::<Option<Option<Option<...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>`
+ --> $DIR/infinite-instantiation.rs:22:9
+ |
+LL | function(counter - 1, t.to_option());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: `function` defined here
+ --> $DIR/infinite-instantiation.rs:20:1
+ |
+LL | fn function<T:ToOpt + Clone>(counter: usize, t: T) {
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ = note: the full type name has been written to '$TEST_BUILD_DIR/infinite/infinite-instantiation/infinite-instantiation.long-type.txt'
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/infinite/infinite-macro-expansion.rs b/src/test/ui/infinite/infinite-macro-expansion.rs
new file mode 100644
index 000000000..6ea0bc73d
--- /dev/null
+++ b/src/test/ui/infinite/infinite-macro-expansion.rs
@@ -0,0 +1,7 @@
+macro_rules! recursive {
+ () => (recursive!()) //~ ERROR recursion limit reached while expanding `recursive!`
+}
+
+fn main() {
+ recursive!()
+}
diff --git a/src/test/ui/infinite/infinite-macro-expansion.stderr b/src/test/ui/infinite/infinite-macro-expansion.stderr
new file mode 100644
index 000000000..15654dfaf
--- /dev/null
+++ b/src/test/ui/infinite/infinite-macro-expansion.stderr
@@ -0,0 +1,14 @@
+error: recursion limit reached while expanding `recursive!`
+ --> $DIR/infinite-macro-expansion.rs:2:12
+ |
+LL | () => (recursive!())
+ | ^^^^^^^^^^^^
+...
+LL | recursive!()
+ | ------------ in this macro invocation
+ |
+ = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`infinite_macro_expansion`)
+ = note: this error originates in the macro `recursive` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/infinite/infinite-recursion-const-fn.rs b/src/test/ui/infinite/infinite-recursion-const-fn.rs
new file mode 100644
index 000000000..420915311
--- /dev/null
+++ b/src/test/ui/infinite/infinite-recursion-const-fn.rs
@@ -0,0 +1,11 @@
+//https://github.com/rust-lang/rust/issues/31364
+
+const fn a() -> usize {
+ b() //~ ERROR evaluation of constant value failed [E0080]
+}
+const fn b() -> usize {
+ a()
+}
+const ARR: [i32; a()] = [5; 6];
+
+fn main() {}
diff --git a/src/test/ui/infinite/infinite-recursion-const-fn.stderr b/src/test/ui/infinite/infinite-recursion-const-fn.stderr
new file mode 100644
index 000000000..620c9e110
--- /dev/null
+++ b/src/test/ui/infinite/infinite-recursion-const-fn.stderr
@@ -0,0 +1,145 @@
+error[E0080]: evaluation of constant value failed
+ --> $DIR/infinite-recursion-const-fn.rs:4:5
+ |
+LL | b()
+ | ^^^
+ | |
+ | reached the configured maximum number of stack frames
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+ | inside `a` at $DIR/infinite-recursion-const-fn.rs:4:5
+...
+LL | a()
+ | ---
+ | |
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+ | inside `b` at $DIR/infinite-recursion-const-fn.rs:7:5
+LL | }
+LL | const ARR: [i32; a()] = [5; 6];
+ | --- inside `ARR::{constant#0}` at $DIR/infinite-recursion-const-fn.rs:9:18
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/infinite/infinite-struct.rs b/src/test/ui/infinite/infinite-struct.rs
new file mode 100644
index 000000000..74185dc59
--- /dev/null
+++ b/src/test/ui/infinite/infinite-struct.rs
@@ -0,0 +1,9 @@
+struct Take(Take);
+//~^ ERROR has infinite size
+
+// check that we don't hang trying to find the tail of a recursive struct (#79437)
+fn foo() -> Take {
+ Take(loop {})
+}
+
+fn main() {}
diff --git a/src/test/ui/infinite/infinite-struct.stderr b/src/test/ui/infinite/infinite-struct.stderr
new file mode 100644
index 000000000..5a6d13786
--- /dev/null
+++ b/src/test/ui/infinite/infinite-struct.stderr
@@ -0,0 +1,16 @@
+error[E0072]: recursive type `Take` has infinite size
+ --> $DIR/infinite-struct.rs:1:1
+ |
+LL | struct Take(Take);
+ | ^^^^^^^^^^^ ---- recursive without indirection
+ | |
+ | recursive type has infinite size
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Take` representable
+ |
+LL | struct Take(Box<Take>);
+ | ++++ +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/infinite/infinite-tag-type-recursion.rs b/src/test/ui/infinite/infinite-tag-type-recursion.rs
new file mode 100644
index 000000000..87a9e08dd
--- /dev/null
+++ b/src/test/ui/infinite/infinite-tag-type-recursion.rs
@@ -0,0 +1,4 @@
+enum MList { Cons(isize, MList), Nil }
+//~^ ERROR recursive type `MList` has infinite size
+
+fn main() { let a = MList::Cons(10, MList::Cons(11, MList::Nil)); }
diff --git a/src/test/ui/infinite/infinite-tag-type-recursion.stderr b/src/test/ui/infinite/infinite-tag-type-recursion.stderr
new file mode 100644
index 000000000..d2dad4b91
--- /dev/null
+++ b/src/test/ui/infinite/infinite-tag-type-recursion.stderr
@@ -0,0 +1,16 @@
+error[E0072]: recursive type `MList` has infinite size
+ --> $DIR/infinite-tag-type-recursion.rs:1:1
+ |
+LL | enum MList { Cons(isize, MList), Nil }
+ | ^^^^^^^^^^ ----- recursive without indirection
+ | |
+ | recursive type has infinite size
+ |
+help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `MList` representable
+ |
+LL | enum MList { Cons(isize, Box<MList>), Nil }
+ | ++++ +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0072`.
diff --git a/src/test/ui/infinite/infinite-trait-alias-recursion.rs b/src/test/ui/infinite/infinite-trait-alias-recursion.rs
new file mode 100644
index 000000000..ec86744e6
--- /dev/null
+++ b/src/test/ui/infinite/infinite-trait-alias-recursion.rs
@@ -0,0 +1,10 @@
+#![feature(trait_alias)]
+
+trait T1 = T2;
+//~^ ERROR cycle detected when computing the super predicates of `T1`
+
+trait T2 = T3;
+
+trait T3 = T1 + T3;
+
+fn main() {}
diff --git a/src/test/ui/infinite/infinite-trait-alias-recursion.stderr b/src/test/ui/infinite/infinite-trait-alias-recursion.stderr
new file mode 100644
index 000000000..b925b3b01
--- /dev/null
+++ b/src/test/ui/infinite/infinite-trait-alias-recursion.stderr
@@ -0,0 +1,42 @@
+error[E0391]: cycle detected when computing the super predicates of `T1`
+ --> $DIR/infinite-trait-alias-recursion.rs:3:1
+ |
+LL | trait T1 = T2;
+ | ^^^^^^^^
+ |
+note: ...which requires computing the super traits of `T1`...
+ --> $DIR/infinite-trait-alias-recursion.rs:3:12
+ |
+LL | trait T1 = T2;
+ | ^^
+note: ...which requires computing the super predicates of `T2`...
+ --> $DIR/infinite-trait-alias-recursion.rs:6:1
+ |
+LL | trait T2 = T3;
+ | ^^^^^^^^
+note: ...which requires computing the super traits of `T2`...
+ --> $DIR/infinite-trait-alias-recursion.rs:6:12
+ |
+LL | trait T2 = T3;
+ | ^^
+note: ...which requires computing the super predicates of `T3`...
+ --> $DIR/infinite-trait-alias-recursion.rs:8:1
+ |
+LL | trait T3 = T1 + T3;
+ | ^^^^^^^^
+note: ...which requires computing the super traits of `T3`...
+ --> $DIR/infinite-trait-alias-recursion.rs:8:12
+ |
+LL | trait T3 = T1 + T3;
+ | ^^
+ = note: ...which again requires computing the super predicates of `T1`, completing the cycle
+ = note: trait aliases cannot be recursive
+note: cycle used when collecting item types in top-level module
+ --> $DIR/infinite-trait-alias-recursion.rs:3:1
+ |
+LL | trait T1 = T2;
+ | ^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/infinite/infinite-type-alias-mutual-recursion.rs b/src/test/ui/infinite/infinite-type-alias-mutual-recursion.rs
new file mode 100644
index 000000000..5381eedcf
--- /dev/null
+++ b/src/test/ui/infinite/infinite-type-alias-mutual-recursion.rs
@@ -0,0 +1,6 @@
+type X1 = X2;
+//~^ ERROR cycle detected when expanding type alias `X1`
+type X2 = X3;
+type X3 = X1;
+
+fn main() {}
diff --git a/src/test/ui/infinite/infinite-type-alias-mutual-recursion.stderr b/src/test/ui/infinite/infinite-type-alias-mutual-recursion.stderr
new file mode 100644
index 000000000..7f82b2944
--- /dev/null
+++ b/src/test/ui/infinite/infinite-type-alias-mutual-recursion.stderr
@@ -0,0 +1,34 @@
+error[E0391]: cycle detected when expanding type alias `X1`
+ --> $DIR/infinite-type-alias-mutual-recursion.rs:1:11
+ |
+LL | type X1 = X2;
+ | ^^
+ |
+note: ...which requires expanding type alias `X2`...
+ --> $DIR/infinite-type-alias-mutual-recursion.rs:3:11
+ |
+LL | type X2 = X3;
+ | ^^
+note: ...which requires expanding type alias `X3`...
+ --> $DIR/infinite-type-alias-mutual-recursion.rs:4:11
+ |
+LL | type X3 = X1;
+ | ^^
+ = note: ...which again requires expanding type alias `X1`, completing the cycle
+ = note: type aliases cannot be recursive
+ = help: consider using a struct, enum, or union instead to break the cycle
+ = help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
+note: cycle used when collecting item types in top-level module
+ --> $DIR/infinite-type-alias-mutual-recursion.rs:1:1
+ |
+LL | / type X1 = X2;
+LL | |
+LL | | type X2 = X3;
+LL | | type X3 = X1;
+LL | |
+LL | | fn main() {}
+ | |____________^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/infinite/infinite-vec-type-recursion.rs b/src/test/ui/infinite/infinite-vec-type-recursion.rs
new file mode 100644
index 000000000..356818225
--- /dev/null
+++ b/src/test/ui/infinite/infinite-vec-type-recursion.rs
@@ -0,0 +1,4 @@
+type X = Vec<X>;
+//~^ ERROR cycle detected
+
+fn main() { let b: X = Vec::new(); }
diff --git a/src/test/ui/infinite/infinite-vec-type-recursion.stderr b/src/test/ui/infinite/infinite-vec-type-recursion.stderr
new file mode 100644
index 000000000..1e487a5b1
--- /dev/null
+++ b/src/test/ui/infinite/infinite-vec-type-recursion.stderr
@@ -0,0 +1,22 @@
+error[E0391]: cycle detected when expanding type alias `X`
+ --> $DIR/infinite-vec-type-recursion.rs:1:14
+ |
+LL | type X = Vec<X>;
+ | ^
+ |
+ = note: ...which immediately requires expanding type alias `X` again
+ = note: type aliases cannot be recursive
+ = help: consider using a struct, enum, or union instead to break the cycle
+ = help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
+note: cycle used when collecting item types in top-level module
+ --> $DIR/infinite-vec-type-recursion.rs:1:1
+ |
+LL | / type X = Vec<X>;
+LL | |
+LL | |
+LL | | fn main() { let b: X = Vec::new(); }
+ | |____________________________________^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.