Skip to content

Tail calls don't enforce lifetime constraints from return type onto args #144916

@compiler-errors

Description

@compiler-errors

I tried this code:

#![feature(explicit_tail_calls)]

fn link(x: &str) -> &'static str {
    become passthrough(x);
}

fn passthrough<T>(t: T) -> T { t }

fn main() {
    let x = String::from("hello, world");
    let s = link(&x);
    drop(x);
    println!("{s}");
}

I expected to see a borrowck error.

Instead, it compiles which is unsound and causes a segfault.

rustc --version --verbose: nightly 2025-08-04

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-explicit_tail_calls`#![feature(explicit_tail_calls)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-lowLow priorityrequires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions