Skip to content
/ rust Public
forked from rust-lang/rust

Commit bb15724

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#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.
2 parents c1f2309 + 50c659f commit bb15724

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)