Skip to content

Commit ed6077a

Browse files
authored
Rollup merge of rust-lang#147711 - saethlin:GlobalAlloc-safety, r=Amanieu
Clarify that UB will occur, not can/may in GlobalAlloc docs These doc comments start out very clear by saying the caller "must" or "has to" ensure something, but the end with some form of "otherwise undefined behavior may result" which sounds like it is implementation-defined and seems to conflict with the way the paragraph starts. Consistent phrasing makes it clearer that when the safety precondition is violated, UB is encountered. Some of the phrasing here is a bit awkward to me, I don't think we usually say "the behavior is undefined" `@RalfJung` right? But in either case I'm trying to be surgical in my edit here. r? Amanieu
2 parents 6f6a1ce + 72396d9 commit ed6077a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

library/core/src/alloc/global.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub unsafe trait GlobalAlloc {
124124
///
125125
/// # Safety
126126
///
127-
/// `layout` must have non-zero size. Attempting to allocate for a zero-sized `layout` may
127+
/// `layout` must have non-zero size. Attempting to allocate for a zero-sized `layout` will
128128
/// result in undefined behavior.
129129
///
130130
/// (Extension subtraits might provide more specific bounds on
@@ -163,7 +163,7 @@ pub unsafe trait GlobalAlloc {
163163
/// * `layout` is the same layout that was used to allocate that block of
164164
/// memory.
165165
///
166-
/// Otherwise undefined behavior can result.
166+
/// Otherwise the behavior is undefined.
167167
#[stable(feature = "global_alloc", since = "1.28.0")]
168168
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
169169

@@ -173,7 +173,7 @@ pub unsafe trait GlobalAlloc {
173173
/// # Safety
174174
///
175175
/// The caller has to ensure that `layout` has non-zero size. Like `alloc`
176-
/// zero sized `layout` can result in undefined behavior.
176+
/// zero sized `layout` will result in undefined behavior.
177177
/// However the allocated block of memory is guaranteed to be initialized.
178178
///
179179
/// # Errors
@@ -234,7 +234,7 @@ pub unsafe trait GlobalAlloc {
234234
/// does not overflow `isize` (i.e., the rounded value must be less than or
235235
/// equal to `isize::MAX`).
236236
///
237-
/// If these are not followed, undefined behavior can result.
237+
/// If these are not followed, the behavior is undefined.
238238
///
239239
/// (Extension subtraits might provide more specific bounds on
240240
/// behavior, e.g., guarantee a sentinel address or a null pointer

0 commit comments

Comments
 (0)