Skip to content

Commit 7ae6109

Browse files
authored
Merge pull request #2336 from RalfJung/dangling
dangling pointers: turn some consequences of the definition into notes
2 parents 9e185a2 + 42163cf commit 7ae6109

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

‎src/behavior-considered-undefined.md‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,13 @@ r[undefined.dangling]
100100
[dangling]: #dangling-pointers
101101

102102
r[undefined.dangling.def]
103-
A reference/pointer is "dangling" if not all of the bytes it [points to] are part of the same live allocation (so in particular they all have to be part of *some* allocation).
103+
A reference/pointer is "dangling" if not all of the bytes it [points to] are part of the same live [allocation] (so in particular they all have to be part of *some* allocation).
104104

105-
r[undefined.dangling.zero-size]
106-
If the [size is 0][zero-sized], then the pointer is trivially never "dangling" (even if it is a null pointer).
107-
108-
r[undefined.dangling.dynamic-size]
109-
Note that dynamically sized types (such as slices and strings) point to their entire range, so it is important that the length [metadata] is never too large.
105+
> [!NOTE]
106+
> This implies that the dynamic size of a Rust value (as determined by `size_of_val`) must never exceed `isize::MAX`, since it is impossible for a single allocation to be larger than `isize::MAX`.
110107
111-
r[undefined.dangling.alloc-limit]
112-
In particular, the dynamic size of a Rust value (as determined by `size_of_val`) must never exceed `isize::MAX`, since it is impossible for a single allocation to be larger than `isize::MAX`.
108+
> [!NOTE]
109+
> This also implies that if the [size is 0][zero-sized], then the pointer is trivially never "dangling" (even if it is a null pointer).
113110
114111
r[undefined.validity]
115112
## Invalid values
@@ -201,6 +198,7 @@ r[undefined.validity.undef]
201198
[`bool`]: types/boolean.md
202199
[`const`]: items/constant-items.md
203200
[abi]: items/external-blocks.md#abi
201+
[allocation]: core::ptr#allocation
204202
[const contexts]: const-eval.const-context
205203
[`target_feature`]: attributes/codegen.md#the-target_feature-attribute
206204
[`UnsafeCell<U>`]: std::cell::UnsafeCell

0 commit comments

Comments
 (0)