Skip to content

Commit 769fb8a

Browse files
authored
Fix safety comment
The size assertion in the comment was inverted compared to the code. After fixing that the implication that `(new_size >= old_size) => new_size != 0` still doesn't hold so explain why `old_size != 0` at this point.
1 parent dfdfaa1 commit 769fb8a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/std/src/alloc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,9 @@ impl System {
166166
match old_layout.size() {
167167
0 => self.alloc_impl(new_layout, zeroed),
168168

169-
// SAFETY: `new_size` is non-zero as `old_size` is greater than or equal to `new_size`
170-
// as required by safety conditions. Other conditions must be upheld by the caller
169+
// SAFETY: `new_size` is non-zero as `new_size` is greater than or equal to `old_size`
170+
// as required by safety conditions and the `old_size == 0` case was handled in the
171+
// previous match arm. Other conditions must be upheld by the caller
171172
old_size if old_layout.align() == new_layout.align() => unsafe {
172173
let new_size = new_layout.size();
173174

0 commit comments

Comments
 (0)