In C, returning a pointer to a local variable is a classic disaster: the local is destroyed when the function returns, and the caller is left holding a pointer to freed memory. Rust makes this impossible to compile.
The dangling reference, refused
If you try to return a reference to a value created inside a function, the borrow checker stops you: the value will be dropped at the function's end, so the reference would point at freed memory. Rust won't let that reference escape. The error names exactly what's wrong — the value doesn't live long enough.
The fix: return ownership, not a reference
If a function creates a value, it should return the value itself (transferring ownership), not a reference to it. The caller then owns it, and it lives as long as needed. Return references only when they borrow from something the caller already owns — like a parameter passed in.
This is where lifetimes come from
How does the compiler know a reference won't outlive its data? It tracks lifetimes — how long each reference stays valid. Usually it infers them silently. But when a function returns a reference derived from its inputs, you sometimes have to annotate them. That's the entire next track — and now you know exactly what problem it solves.