S0136: cannot return reference to local value
Generated from rellum-diagnostics/src/db.rs.
Explanation
Local bindings and temporaries are dropped when their function or block region ends. Returning a reference to one would let callers observe storage that no longer exists.
Common causes
- returning &x where x is a local binding
- returning a reference to a temporary expression
- capturing a borrowed local in a returned function value
Canonical fixes
- return an owned value instead
Before:
bad() : &Int =
x = 1
&x
After:
ok() : Int =
x = 1
x
- return a reference tied to an input reference instead of a local
Code example
bad() : &Int =
x = 1
&x