E4005
E4005 — A returned reference escapes the function borrowing a function-local (dangling return)
What the compiler reports
E4005
The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.
A program that triggers it
// Return-escape analysis (#243, case bc4): returning `&x` for a function-local `x`
// leaves a dangling reference once the frame unwinds. Must be rejected.
fn dangle() -> &i32 {
let x = 5;
return &x;
}
fn main() -> i32 {
return 0;
}
From tests/middle_end/fail/borrow_return_local_ref.vx, which asserts this diagnostic on every commit.