diff options
Diffstat (limited to 'tests/ui/infinite')
23 files changed, 1106 insertions, 0 deletions
diff --git a/tests/ui/infinite/infinite-autoderef.rs b/tests/ui/infinite/infinite-autoderef.rs new file mode 100644 index 000000000..cbbe1f81d --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-autoderef.stderr b/tests/ui/infinite/infinite-autoderef.stderr new file mode 100644 index 000000000..51b61e3a6 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-instantiation.polonius.stderr b/tests/ui/infinite/infinite-instantiation.polonius.stderr new file mode 100644 index 000000000..29eb8c481 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-instantiation.rs b/tests/ui/infinite/infinite-instantiation.rs new file mode 100644 index 000000000..9b9f332ca --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-instantiation.stderr b/tests/ui/infinite/infinite-instantiation.stderr new file mode 100644 index 000000000..951e0f587 --- /dev/null +++ b/tests/ui/infinite/infinite-instantiation.stderr @@ -0,0 +1,15 @@ +error: reached the recursion limit while instantiating `function::<Option<Option<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/tests/ui/infinite/infinite-macro-expansion.rs b/tests/ui/infinite/infinite-macro-expansion.rs new file mode 100644 index 000000000..6ea0bc73d --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-macro-expansion.stderr b/tests/ui/infinite/infinite-macro-expansion.stderr new file mode 100644 index 000000000..15654dfaf --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-recursion-const-fn.rs b/tests/ui/infinite/infinite-recursion-const-fn.rs new file mode 100644 index 000000000..420915311 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-recursion-const-fn.stderr b/tests/ui/infinite/infinite-recursion-const-fn.stderr new file mode 100644 index 000000000..53b603a47 --- /dev/null +++ b/tests/ui/infinite/infinite-recursion-const-fn.stderr @@ -0,0 +1,650 @@ +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 + | +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `b` + --> $DIR/infinite-recursion-const-fn.rs:7:5 + | +LL | a() + | ^^^ +note: inside `a` + --> $DIR/infinite-recursion-const-fn.rs:4:5 + | +LL | b() + | ^^^ +note: inside `ARR::{constant#0}` + --> $DIR/infinite-recursion-const-fn.rs:9:18 + | +LL | const ARR: [i32; a()] = [5; 6]; + | ^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/infinite/infinite-struct.rs b/tests/ui/infinite/infinite-struct.rs new file mode 100644 index 000000000..f08e10f6b --- /dev/null +++ b/tests/ui/infinite/infinite-struct.rs @@ -0,0 +1,16 @@ +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 {}) +} + +// mutually infinite structs +struct Foo { //~ ERROR has infinite size + x: Bar<Foo>, +} + +struct Bar<T>([T; 1]); + +fn main() {} diff --git a/tests/ui/infinite/infinite-struct.stderr b/tests/ui/infinite/infinite-struct.stderr new file mode 100644 index 000000000..b6c72b1de --- /dev/null +++ b/tests/ui/infinite/infinite-struct.stderr @@ -0,0 +1,27 @@ +error[E0072]: recursive type `Take` has infinite size + --> $DIR/infinite-struct.rs:1:1 + | +LL | struct Take(Take); + | ^^^^^^^^^^^ ---- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | struct Take(Box<Take>); + | ++++ + + +error[E0072]: recursive type `Foo` has infinite size + --> $DIR/infinite-struct.rs:10:1 + | +LL | struct Foo { + | ^^^^^^^^^^ +LL | x: Bar<Foo>, + | --- recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | x: Bar<Box<Foo>>, + | ++++ + + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0072`. diff --git a/tests/ui/infinite/infinite-tag-type-recursion.rs b/tests/ui/infinite/infinite-tag-type-recursion.rs new file mode 100644 index 000000000..87a9e08dd --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-tag-type-recursion.stderr b/tests/ui/infinite/infinite-tag-type-recursion.stderr new file mode 100644 index 000000000..513bbfc1b --- /dev/null +++ b/tests/ui/infinite/infinite-tag-type-recursion.stderr @@ -0,0 +1,14 @@ +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 + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +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/tests/ui/infinite/infinite-trait-alias-recursion.rs b/tests/ui/infinite/infinite-trait-alias-recursion.rs new file mode 100644 index 000000000..ec86744e6 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-trait-alias-recursion.stderr b/tests/ui/infinite/infinite-trait-alias-recursion.stderr new file mode 100644 index 000000000..b925b3b01 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs b/tests/ui/infinite/infinite-type-alias-mutual-recursion.rs new file mode 100644 index 000000000..5381eedcf --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-type-alias-mutual-recursion.stderr b/tests/ui/infinite/infinite-type-alias-mutual-recursion.stderr new file mode 100644 index 000000000..7f82b2944 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-vec-type-recursion.rs b/tests/ui/infinite/infinite-vec-type-recursion.rs new file mode 100644 index 000000000..356818225 --- /dev/null +++ b/tests/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/tests/ui/infinite/infinite-vec-type-recursion.stderr b/tests/ui/infinite/infinite-vec-type-recursion.stderr new file mode 100644 index 000000000..1e487a5b1 --- /dev/null +++ b/tests/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`. diff --git a/tests/ui/infinite/issue-41731-infinite-macro-print.rs b/tests/ui/infinite/issue-41731-infinite-macro-print.rs new file mode 100644 index 000000000..d52e6e7e9 --- /dev/null +++ b/tests/ui/infinite/issue-41731-infinite-macro-print.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + print!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/tests/ui/infinite/issue-41731-infinite-macro-print.stderr b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr new file mode 100644 index 000000000..e30b2039d --- /dev/null +++ b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args!` + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_print`) + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `print! (stack! ("overflow")) ;` + = note: expanding `print! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-print.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | print!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/infinite/issue-41731-infinite-macro-println.rs b/tests/ui/infinite/issue-41731-infinite-macro-println.rs new file mode 100644 index 000000000..3c2b7ee02 --- /dev/null +++ b/tests/ui/infinite/issue-41731-infinite-macro-println.rs @@ -0,0 +1,15 @@ +// compile-flags: -Z trace-macros + +#![recursion_limit = "5"] + +fn main() { + macro_rules! stack { + ($overflow:expr) => { + println!(stack!($overflow)); + //~^ ERROR recursion limit reached while expanding + //~| ERROR format argument must be a string literal + }; + } + + stack!("overflow"); +} diff --git a/tests/ui/infinite/issue-41731-infinite-macro-println.stderr b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr new file mode 100644 index 000000000..66b466daf --- /dev/null +++ b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr @@ -0,0 +1,38 @@ +error: recursion limit reached while expanding `$crate::format_args_nl!` + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = help: consider increasing the recursion limit by adding a `#![recursion_limit = "10"]` attribute to your crate (`issue_41731_infinite_macro_println`) + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) + +note: trace_macro + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + = note: expanding `stack! { "overflow" }` + = note: to `println! (stack! ("overflow")) ;` + = note: expanding `println! { stack! ("overflow") }` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }` + +error: format argument must be a string literal + --> $DIR/issue-41731-infinite-macro-println.rs:14:5 + | +LL | stack!("overflow"); + | ^^^^^^^^^^^^^^^^^^ + | + = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you might be missing a string literal to format with + | +LL | println!("{}", stack!($overflow)); + | +++++ + +error: aborting due to 2 previous errors + |