Rollup merge of #148846 - folkertdev:tail-call-rpit, r=WaffleLapkin

add a test for combining RPIT with explicit tail calls

tracking issue: https://github.com/rust-lang/rust/issues/112788
fixes 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 any more.

Using RPIT probably should work, see also https://github.com/rust-lang/rust/issues/144953.

The snippet in the issue is not valid for a variety of reasons, and based on the assert that got triggered the ICE was just any `-> impl Trait` at all, so I've made a minimal example using RPIT.

r? `@WaffleLapkin`
This commit is contained in:
Stuart Cook 2025-11-13 11:57:09 +11:00 committed by GitHub
commit 1f2d7db112
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -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");
}

View file

@ -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