Skip to content

Commit 816e029

Browse files
authored
Rollup merge of rust-lang#111301 - JohnBobbo96:cleanup_option_insert_methods, r=scottmcm
Remove calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`. This removes the unneeded calls to `mem::forget` and `mem::replace` in `Option::get_or_insert_with`.
2 parents 88a0204 + ec7fcdc commit 816e029

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

library/core/src/option.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1641,10 +1641,8 @@ impl<T> Option<T> {
16411641
where
16421642
F: FnOnce() -> T,
16431643
{
1644-
if let None = *self {
1645-
// the compiler isn't smart enough to know that we are not dropping a `T`
1646-
// here and wants us to ensure `T` can be dropped at compile time.
1647-
mem::forget(mem::replace(self, Some(f())))
1644+
if let None = self {
1645+
*self = Some(f());
16481646
}
16491647

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

0 commit comments

Comments
 (0)