diff --git a/library/core/src/option.rs b/library/core/src/option.rs index c38c68e1d5867..ec1ef3cf43d12 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -1641,10 +1641,8 @@ impl Option { 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`