From c7ea022166d2b6d55c3f69bbf69a31b0d7b053e2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 4 Aug 2025 16:24:41 +0000 Subject: Enforce tail call type is related to body return type in borrowck --- .../explicit-tail-calls/ret-ty-borrowck-constraints.rs | 16 ++++++++++++++++ .../ret-ty-borrowck-constraints.stderr | 10 ++++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs create mode 100644 tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.stderr (limited to 'tests') 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 } + +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 + -- cgit 1.4.1-3-g733a5