Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense to me, though -- the forget+replace is a residue from when this was unstably const, before that was undone.

}

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