about summary refs log tree commit diff
path: root/src/libcore/option.rs
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-07-04 01:39:01 +0200
committerGitHub <noreply@github.com>2019-07-04 01:39:01 +0200
commit839e89c3d113ac80bc1bdc9383a3cd64ba4e9582 (patch)
tree13a3923806856502c39a2158a8a85b37093d6d29 /src/libcore/option.rs
parentcd1fa00446e438407f58a0c9d70c712a8e4f1e80 (diff)
parentc51802ac6087206e302bbded174d5ac9feabf2b7 (diff)
downloadrust-839e89c3d113ac80bc1bdc9383a3cd64ba4e9582.tar.gz
rust-839e89c3d113ac80bc1bdc9383a3cd64ba4e9582.zip
Rollup merge of #62344 - matklad:simplify-option, r=sfackler
simplify Option::get_or_insert

I am pretty sure that the optimized result will be the same, and it's one `unsafe` less in the stdlib!
Diffstat (limited to 'src/libcore/option.rs')
-rw-r--r--src/libcore/option.rs10
1 files changed, 1 insertions, 9 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index a2eff0200b7..b27fd4098e1 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -777,15 +777,7 @@ impl<T> Option<T> {
     #[inline]
     #[stable(feature = "option_entry", since = "1.20.0")]
     pub fn get_or_insert(&mut self, v: T) -> &mut T {
-        match *self {
-            None => *self = Some(v),
-            _ => (),
-        }
-
-        match *self {
-            Some(ref mut v) => v,
-            None => unsafe { hint::unreachable_unchecked() },
-        }
+        self.get_or_insert_with(|| v)
     }
 
     /// Inserts a value computed from `f` into the option if it is [`None`], then