Skip to content

Commit 50c659f

Browse files
committed
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.
1 parent f7b4354 commit 50c659f

File tree

1 file changed

+6
-3
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+6
-3
lines changed

compiler/rustc_error_codes/src/error_codes/E0515.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
1717
}
1818
```
1919

20-
Local variables, function parameters and temporaries are all dropped before the
21-
end of the function body. So a reference to them cannot be returned.
20+
Local variables, function parameters and temporaries are all dropped before
21+
the end of the function body. A returned reference (or struct containing a
22+
reference) to such a dropped value would immediately be invalid. Therefore
23+
it is not allowed to return such a reference.
2224

23-
Consider returning an owned value instead:
25+
Consider returning a value that takes ownership of local data instead of
26+
referencing it:
2427

2528
```
2629
use std::vec::IntoIter;

0 commit comments

Comments
 (0)