diff options
| author | Marijn Schouten <hkBst@users.noreply.github.com> | 2025-03-14 17:30:47 +0100 |
|---|---|---|
| committer | Marijn Schouten <mhkbst@gmail.com> | 2025-03-14 19:28:59 +0100 |
| commit | 50c659fcba19f6d51d465815cadcea00d8abb02b (patch) | |
| tree | 1ee8dfd2716c826d0a488213ca8d17baa7f9a8d8 /compiler/rustc_error_codes | |
| parent | f7b43542838f0a4a6cfdb17fbeadf45002042a77 (diff) | |
| download | rust-50c659fcba19f6d51d465815cadcea00d8abb02b.tar.gz rust-50c659fcba19f6d51d465815cadcea00d8abb02b.zip | |
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.
Diffstat (limited to 'compiler/rustc_error_codes')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0515.md | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0515.md b/compiler/rustc_error_codes/src/error_codes/E0515.md index 0f4fbf67223..87bbe4aea70 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0515.md +++ b/compiler/rustc_error_codes/src/error_codes/E0515.md @@ -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; |
