Open
Conversation
made the language around immutable target of references more direct
julian-graf
reviewed
Jan 13, 2026
| verifying that references don't escape the scope of their referent. That's | ||
| because ensuring pointers are always valid is much more complicated than this. | ||
| Of course, Rust's story around ownership is much more complicated than simply | ||
| gauranteeing that references cannot outlive their target. That is |
Contributor
There was a problem hiding this comment.
Suggested change
| gauranteeing that references cannot outlive their target. That is | |
| guaranteeing that references cannot outlive their target. That is |
| referent and its owners. | ||
| a naive scope analysis would be insufficient to prevent this bug because `data` | ||
| does indeed live as long as required. However, `data` is *changed* by `push(4)` | ||
| and now may have been realocated to accommodate the new value. |
Contributor
There was a problem hiding this comment.
Suggested change
| and now may have been realocated to accommodate the new value. | |
| and now may have been reallocated to accommodate the new value. |
Comment on lines
+65
to
+66
| Consequently, `x` may now be referring to the old | ||
| value or memory already put to use in another process (pre-emptive multi-tasking). |
Contributor
There was a problem hiding this comment.
Going into detail this far (another process & preemptive multitasking) is misleading in multiple ways:
- the actual issue of accessing free'd memory is not mentioned
- accessing free'd memory is UB
- another process & preemptive multitasking is not a requirement
Suggested change
| Consequently, `x` may now be referring to the old | |
| value or memory already put to use in another process (pre-emptive multi-tasking). | |
| Consequently, the memory location pointed to by `x` may now be free'd and therefore any attempt to dereference `x` is UB. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
made the language around immutable target of references more direct