about summary refs log tree commit diff
path: root/tests/ui/explicit-tail-calls
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2025-08-04 16:24:41 +0000
committerMichael Goulet <michael@errs.io>2025-08-04 16:35:58 +0000
commitc7ea022166d2b6d55c3f69bbf69a31b0d7b053e2 (patch)
tree1ff6f1889d61e209d6dc0ffa38906e08db87e5eb /tests/ui/explicit-tail-calls
parente1b9081e699065badfc1a9419ec9566e5c8615c4 (diff)
downloadrust-c7ea022166d2b6d55c3f69bbf69a31b0d7b053e2.tar.gz
rust-c7ea022166d2b6d55c3f69bbf69a31b0d7b053e2.zip
Enforce tail call type is related to body return type in borrowck
Diffstat (limited to 'tests/ui/explicit-tail-calls')
-rw-r--r--tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs16
-rw-r--r--tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.stderr10
2 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs b/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs
new file mode 100644
index 00000000000..111ae849c0f
--- /dev/null
+++ b/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs
@@ -0,0 +1,16 @@
+#![feature(explicit_tail_calls)]
+#![expect(incomplete_features)]
+
+fn link(x: &str) -> &'static str {
+    become passthrough(x);
+    //~^ ERROR lifetime may not live long enough
+}
+
+fn passthrough<T>(t: T) -> T { t }
+
+fn main() {
+    let x = String::from("hello, world");
+    let s = link(&x);
+    drop(x);
+    println!("{s}");
+}
diff --git a/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.stderr b/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.stderr
new file mode 100644
index 00000000000..26a8e1f0122
--- /dev/null
+++ b/tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.stderr
@@ -0,0 +1,10 @@
+error: lifetime may not live long enough
+  --> $DIR/ret-ty-borrowck-constraints.rs:5:5
+   |
+LL | fn link(x: &str) -> &'static str {
+   |            - let's call the lifetime of this reference `'1`
+LL |     become passthrough(x);
+   |     ^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
+
+error: aborting due to 1 previous error
+