Commit 16a0d03
committed
Auto merge of rust-lang#97521 - SkiFire13:clarify-vec-as-ptr, r=Dylan-DPC
Clarify the guarantees of Vec::as_ptr and Vec::as_mut_ptr when there's no allocation
Currently the documentation says they return a pointer to the vector's buffer, which has the implied precondition that the vector allocated some memory. However `Vec`'s documentation also specifies that it won't always allocate, so it's unclear whether the pointer returned is valid in that case. Of course you won't be able to read/write actual bytes to/from it since the capacity is 0, but there's an exception: zero sized read/writes. They are still valid as long as the pointer is not null and the memory it points to wasn't deallocated, but `Vec::as_ptr` and `Vec::as_mut_ptr` don't specify that's not the case. This PR thus specifies they are actually valid for zero sized reads since `Vec` is implemented to hold a dangling pointer in those cases, which is neither null nor was deallocated.1 file changed
+4
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | | - | |
| 1110 | + | |
| 1111 | + | |
1111 | 1112 | | |
1112 | 1113 | | |
1113 | 1114 | | |
| |||
1144 | 1145 | | |
1145 | 1146 | | |
1146 | 1147 | | |
1147 | | - | |
| 1148 | + | |
| 1149 | + | |
1148 | 1150 | | |
1149 | 1151 | | |
1150 | 1152 | | |
| |||
0 commit comments