Skip to content

Commit

Permalink
Rollup merge of rust-lang#80774 - LingMan:patch-1, r=nagisa
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Jan 10, 2021
2 parents 36d8242 + 769fb8a commit 6f062df
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ impl System {
match old_layout.size() {
0 => self.alloc_impl(new_layout, zeroed),

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

Expand Down

0 comments on commit 6f062df

Please sign in to comment.