Enforce tail call type is related to body return type in borrowck
This commit is contained in:
parent
e1b9081e69
commit
c7ea022166
3 changed files with 33 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
16
tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs
Normal file
16
tests/ui/explicit-tail-calls/ret-ty-borrowck-constraints.rs
Normal 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}");
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue