Rollup merge of #138508 - hkBst:patch-3, r=wesleywiser
Clarify "owned data" in E0515.md This clarifies the explanation of why this is not allowed and also what to do instead. Fixes #62071 PS There was suggestion of adding a link to the book. I did not yet do that, but if desired that could be added.
This commit is contained in:
commit
01062ba233
1 changed files with 6 additions and 3 deletions
|
@ -17,10 +17,13 @@ fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
|
|||
}
|
||||
```
|
||||
|
||||
Local variables, function parameters and temporaries are all dropped before the
|
||||
end of the function body. So a reference to them cannot be returned.
|
||||
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 an owned value instead:
|
||||
Consider returning a value that takes ownership of local data instead of
|
||||
referencing it:
|
||||
|
||||
```
|
||||
use std::vec::IntoIter;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue