Enforce tail call type is related to body return type in borrowck

This commit is contained in:
Michael Goulet 2025-08-04 16:24:41 +00:00
parent e1b9081e69
commit c7ea022166
3 changed files with 33 additions and 3 deletions

View file

@ -845,9 +845,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
);
}
if let TerminatorKind::Call { destination, target, .. } = term.kind {
self.check_call_dest(term, &sig, destination, target, term_location);
}
let (destination, target) =
if let TerminatorKind::Call { destination, target, .. } = term.kind {
(destination, target)
} else {
(RETURN_PLACE.into(), Some(BasicBlock::ZERO))
};
self.check_call_dest(term, &sig, destination, target, term_location);
// The ordinary liveness rules will ensure that all
// regions in the type of the callee are live here. We

View file

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

View file

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