Error code E0515
A reference to a local variable was returned.
Erroneous code example:
ⓘ
ⓘ
Local variables, function parameters and temporaries are all dropped before the end of the function body. A returned reference (or struct containing a reference) to such a dropped value would immediately be invalid. Therefore it is not allowed to return such a reference.
Consider returning a value that takes ownership of local data instead of referencing it: