Skip to content

Commit

Permalink
Remove unneeded calls to mem::forget
Browse files Browse the repository at this point in the history
and `mem::replace` in `Option::get_or_insert_with`.
  • Loading branch information
JohnBobbo96 committed May 6, 2023
1 parent 905d5a3 commit ec7fcdc
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,10 +1641,8 @@ impl<T> Option<T> {
where
F: FnOnce() -> T,
{
if let None = *self {
// the compiler isn't smart enough to know that we are not dropping a `T`
// here and wants us to ensure `T` can be dropped at compile time.
mem::forget(mem::replace(self, Some(f())))
if let None = self {
*self = Some(f());
}

// SAFETY: a `None` variant for `self` would have been replaced by a `Some`
Expand Down

0 comments on commit ec7fcdc

Please sign in to comment.