From f5f91cc4a740dace9a882d35d5e28dc6d4aefe56 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Wed, 12 Nov 2025 00:00:39 +0100 Subject: [PATCH] add a test for combining RPIT with explicit tail calls --- tests/ui/explicit-tail-calls/rpit.rs | 20 ++++++++++++++++++++ tests/ui/explicit-tail-calls/rpit.stderr | 12 ++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/ui/explicit-tail-calls/rpit.rs create mode 100644 tests/ui/explicit-tail-calls/rpit.stderr diff --git a/tests/ui/explicit-tail-calls/rpit.rs b/tests/ui/explicit-tail-calls/rpit.rs new file mode 100644 index 0000000000000..0d1f2c78fd13d --- /dev/null +++ b/tests/ui/explicit-tail-calls/rpit.rs @@ -0,0 +1,20 @@ +#![feature(explicit_tail_calls)] +#![expect(incomplete_features)] + +// Regression test for https://github.com/rust-lang/rust/issues/139305. +// +// Combining return position impl trait (RPIT) with guaranteed tail calls does not +// currently work, but at least it does not ICE. + +fn foo(x: u32, y: u32) -> u32 { + x + y +} + +fn bar(x: u32, y: u32) -> impl ToString { + become foo(x, y); + //~^ ERROR mismatched signatures +} + +fn main() { + assert_eq!(bar(1, 2).to_string(), "3"); +} diff --git a/tests/ui/explicit-tail-calls/rpit.stderr b/tests/ui/explicit-tail-calls/rpit.stderr new file mode 100644 index 0000000000000..9c181db8b8019 --- /dev/null +++ b/tests/ui/explicit-tail-calls/rpit.stderr @@ -0,0 +1,12 @@ +error: mismatched signatures + --> $DIR/rpit.rs:14:5 + | +LL | become foo(x, y); + | ^^^^^^^^^^^^^^^^ + | + = note: `become` requires caller and callee to have matching signatures + = note: caller signature: `fn(u32, u32) -> impl ToString` + = note: callee signature: `fn(u32, u32) -> u32` + +error: aborting due to 1 previous error +