about summary refs log tree commit diff
path: root/tests/ui/recursion
diff options
context:
space:
mode:
authorOneirical <manchot@videotron.ca>2025-07-13 16:56:31 -0400
committerOneirical <manchot@videotron.ca>2025-08-17 13:01:02 -0400
commit75e0263af9ca27eac2c922538582deec764d1e7b (patch)
treebc8584c15f51966d5ddee98a6782785d5c158fe0 /tests/ui/recursion
parent2e2642e641a941f0a1400c7827fd89aa86fef8f4 (diff)
downloadrust-75e0263af9ca27eac2c922538582deec764d1e7b.tar.gz
rust-75e0263af9ca27eac2c922538582deec764d1e7b.zip
Rehome tests/ui/issues/ tests [5/?]
Diffstat (limited to 'tests/ui/recursion')
-rw-r--r--tests/ui/recursion/infinite-function-recursion-error-8727.rs16
-rw-r--r--tests/ui/recursion/infinite-function-recursion-error-8727.stderr27
2 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/recursion/infinite-function-recursion-error-8727.rs b/tests/ui/recursion/infinite-function-recursion-error-8727.rs
new file mode 100644
index 00000000000..a4037f76109
--- /dev/null
+++ b/tests/ui/recursion/infinite-function-recursion-error-8727.rs
@@ -0,0 +1,16 @@
+// https://github.com/rust-lang/rust/issues/8727
+// Verify the compiler fails with an error on infinite function
+// recursions.
+
+//@ build-fail
+//@ compile-flags: --diagnostic-width=100 -Zwrite-long-types-to-disk=yes
+
+fn generic<T>() { //~ WARN function cannot return without recursing
+    generic::<Option<T>>();
+}
+//~^^ ERROR reached the recursion limit while instantiating `generic::<Option<
+
+fn main () {
+    // Use generic<T> at least once to trigger instantiation.
+    generic::<i32>();
+}
diff --git a/tests/ui/recursion/infinite-function-recursion-error-8727.stderr b/tests/ui/recursion/infinite-function-recursion-error-8727.stderr
new file mode 100644
index 00000000000..13d57ecb3b2
--- /dev/null
+++ b/tests/ui/recursion/infinite-function-recursion-error-8727.stderr
@@ -0,0 +1,27 @@
+warning: function cannot return without recursing
+  --> $DIR/infinite-function-recursion-error-8727.rs:8:1
+   |
+LL | fn generic<T>() {
+   | ^^^^^^^^^^^^^^^ cannot return without recursing
+LL |     generic::<Option<T>>();
+   |     ---------------------- recursive call site
+   |
+   = help: a `loop` may express intention better if this is on purpose
+   = note: `#[warn(unconditional_recursion)]` on by default
+
+error: reached the recursion limit while instantiating `generic::<Option<Option<Option<Option<...>>>>>`
+  --> $DIR/infinite-function-recursion-error-8727.rs:9:5
+   |
+LL |     generic::<Option<T>>();
+   |     ^^^^^^^^^^^^^^^^^^^^^^
+   |
+note: `generic` defined here
+  --> $DIR/infinite-function-recursion-error-8727.rs:8:1
+   |
+LL | fn generic<T>() {
+   | ^^^^^^^^^^^^^^^
+   = note: the full name for the type has been written to '$TEST_BUILD_DIR/infinite-function-recursion-error-8727.long-type-$LONG_TYPE_HASH.txt'
+   = note: consider using `--verbose` to print the full type name to the console
+
+error: aborting due to 1 previous error; 1 warning emitted
+