From 9ae00ff864027966a58a965bdf9f2118baafd676 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 23 Aug 2026 23:12:12 +0200 Subject: [PATCH 1/2] dangling pointers: turn some consequences of the definition into notes --- src/behavior-considered-undefined.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 935f0dd9fa..1543330a9e 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -100,16 +100,13 @@ r[undefined.dangling] [dangling]: #dangling-pointers r[undefined.dangling.def] -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). +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). -r[undefined.dangling.zero-size] -If the [size is 0][zero-sized], then the pointer is trivially never "dangling" (even if it is a null pointer). - -r[undefined.dangling.dynamic-size] -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. +> [!NOTE] +> 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`. -r[undefined.dangling.alloc-limit] -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`. +> [!NOTE] +> 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). r[undefined.validity] ## Invalid values @@ -201,6 +198,7 @@ r[undefined.validity.undef] [`bool`]: types/boolean.md [`const`]: items/constant-items.md [abi]: items/external-blocks.md#abi +[allocation]: ../std/ptr/index.html#allocation [const contexts]: const-eval.const-context [`target_feature`]: attributes/codegen.md#the-target_feature-attribute [`UnsafeCell`]: std::cell::UnsafeCell From 42163cfd888fe8e0b4a0ded1659d5eade3c9988f Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Tue, 1 Sep 2026 19:18:42 +0000 Subject: [PATCH 2/2] Use an intra-doc path for the allocation link Our tooling supports link reference definitions of the form `core::ptr#allocation`, so let's use that. --- src/behavior-considered-undefined.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/behavior-considered-undefined.md b/src/behavior-considered-undefined.md index 1543330a9e..ff34d0af28 100644 --- a/src/behavior-considered-undefined.md +++ b/src/behavior-considered-undefined.md @@ -198,7 +198,7 @@ r[undefined.validity.undef] [`bool`]: types/boolean.md [`const`]: items/constant-items.md [abi]: items/external-blocks.md#abi -[allocation]: ../std/ptr/index.html#allocation +[allocation]: core::ptr#allocation [const contexts]: const-eval.const-context [`target_feature`]: attributes/codegen.md#the-target_feature-attribute [`UnsafeCell`]: std::cell::UnsafeCell