Skip to content

Commit 6150ad2

Browse files
authored
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 6150ad2

File tree

1 file changed

+4
-2
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+4
-2
lines changed

compiler/rustc_error_codes/src/error_codes/E0515.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ fn get_dangling_iterator<'a>() -> Iter<'a, i32> {
1818
```
1919

2020
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.
21+
end of the function body. A returned reference (or struct containing a reference)
22+
to such a dropped value would immediately become invalid. Therefore it is not
23+
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:
2426

2527
```
2628
use std::vec::IntoIter;

0 commit comments

Comments
 (0)