about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-07-03 20:17:05 +0300
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-07-03 20:17:05 +0300
commitc51802ac6087206e302bbded174d5ac9feabf2b7 (patch)
tree3470bb8cdfe812a6a3f43144a83e5cdd0bb7c255
parent8301de16dafc81a3b5d94aa0707ad83bdb56a599 (diff)
simplify Option::get_or_insert
-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 eec4b149ddc..41b6d53f765 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