diff options
| author | John Bobbo <johnbobbo59@gmail.com> | 2023-05-06 14:42:07 -0700 |
|---|---|---|
| committer | John Bobbo <johnbobbo59@gmail.com> | 2023-05-06 14:42:07 -0700 |
| commit | ec7fcdc959872d7ba9e1d20fa598a3f95678885b (patch) | |
| tree | fae00d777ae41742f6b84d8eda202d2faaa844e1 | |
| parent | 905d5a38d69328385ce9963c65c385734c60322d (diff) | |
| download | rust-ec7fcdc959872d7ba9e1d20fa598a3f95678885b.tar.gz rust-ec7fcdc959872d7ba9e1d20fa598a3f95678885b.zip | |
Remove unneeded calls to `mem::forget`
and `mem::replace` in `Option::get_or_insert_with`.
| -rw-r--r-- | library/core/src/option.rs | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index c38c68e1d58..ec1ef3cf43d 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -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` |
