@@ -125,8 +125,8 @@ pub unsafe trait GlobalAlloc {
125
125
///
126
126
/// # Safety
127
127
///
128
- /// This function is unsafe because undefined behavior can result
129
- /// if the caller does not ensure that `layout` has non-zero size .
128
+ /// The caller has to ensure that `layout` has non-zero size. Zero sized
129
+ /// `layout` can result in undefined behaviour .
130
130
///
131
131
/// (Extension subtraits might provide more specific bounds on
132
132
/// behavior, e.g., guarantee a sentinel address or a null pointer
@@ -157,14 +157,14 @@ pub unsafe trait GlobalAlloc {
157
157
///
158
158
/// # Safety
159
159
///
160
- /// This function is unsafe because undefined behavior can result
161
- /// if the caller does not ensure all of the following:
160
+ /// The caller has to ensure that
162
161
///
163
- /// * `ptr` must denote a block of memory currently allocated via
164
- /// this allocator,
162
+ /// * `ptr` is a block of memory currently allocated via this allocator and,
165
163
///
166
- /// * `layout` must be the same layout that was used
167
- /// to allocate that block of memory.
164
+ /// * `layout` is the same layout that was used to allocate that block of
165
+ /// memory.
166
+ ///
167
+ /// Otherwise undefined behavior can result.
168
168
#[ stable( feature = "global_alloc" , since = "1.28.0" ) ]
169
169
unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) ;
170
170
@@ -173,7 +173,8 @@ pub unsafe trait GlobalAlloc {
173
173
///
174
174
/// # Safety
175
175
///
176
- /// This function is unsafe for the same reasons that `alloc` is.
176
+ /// The caller has to ensure that `layout` has non-zero size. Like `alloc`
177
+ /// zero sized `layout` can result in undefined behaviour.
177
178
/// However the allocated block of memory is guaranteed to be initialized.
178
179
///
179
180
/// # Errors
@@ -221,20 +222,21 @@ pub unsafe trait GlobalAlloc {
221
222
///
222
223
/// # Safety
223
224
///
224
- /// This function is unsafe because undefined behavior can result
225
- /// if the caller does not ensure all of the following:
225
+ /// The caller has to ensure that
226
226
///
227
- /// * `ptr` must be currently allocated via this allocator,
227
+ /// * `ptr` is allocated via this allocator,
228
228
///
229
- /// * `layout` must be the same layout that was used
229
+ /// * `layout` is the same layout that was used
230
230
/// to allocate that block of memory,
231
231
///
232
- /// * `new_size` must be greater than zero.
232
+ /// * `new_size` is greater than zero.
233
233
///
234
234
/// * `new_size`, when rounded up to the nearest multiple of `layout.align()`,
235
- /// must not overflow isize (i.e., the rounded value must be less than or
235
+ /// does not overflow isize (i.e., the rounded value must be less than or
236
236
/// equal to `isize::MAX`).
237
237
///
238
+ /// Otherwise undefined behaviour can result.
239
+ ///
238
240
/// (Extension subtraits might provide more specific bounds on
239
241
/// behavior, e.g., guarantee a sentinel address or a null pointer
240
242
/// in response to a zero-size allocation request.)
0 commit comments