Skip to content

Commit c7ea022

Browse files
Enforce tail call type is related to body return type in borrowck
1 parent e1b9081 commit c7ea022

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,9 +845,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
845845
);
846846
}
847847

848-
if let TerminatorKind::Call { destination, target, .. } = term.kind {
849-
self.check_call_dest(term, &sig, destination, target, term_location);
850-
}
848+
let (destination, target) =
849+
if let TerminatorKind::Call { destination, target, .. } = term.kind {
850+
(destination, target)
851+
} else {
852+
(RETURN_PLACE.into(), Some(BasicBlock::ZERO))
853+
};
854+
self.check_call_dest(term, &sig, destination, target, term_location);
851855

852856
// The ordinary liveness rules will ensure that all
853857
// regions in the type of the callee are live here. We
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(explicit_tail_calls)]
2+
#![expect(incomplete_features)]
3+
4+
fn link(x: &str) -> &'static str {
5+
become passthrough(x);
6+
//~^ ERROR lifetime may not live long enough
7+
}
8+
9+
fn passthrough<T>(t: T) -> T { t }
10+
11+
fn main() {
12+
let x = String::from("hello, world");
13+
let s = link(&x);
14+
drop(x);
15+
println!("{s}");
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: lifetime may not live long enough
2+
--> $DIR/ret-ty-borrowck-constraints.rs:5:5
3+
|
4+
LL | fn link(x: &str) -> &'static str {
5+
| - let's call the lifetime of this reference `'1`
6+
LL | become passthrough(x);
7+
| ^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)