]> git.lizzy.rs Git - rust.git/commitdiff
Rename Option::get_or_insert_default
authorCameron Steffen <cam.steffen94@gmail.com>
Wed, 10 Mar 2021 14:48:09 +0000 (08:48 -0600)
committerCameron Steffen <cam.steffen94@gmail.com>
Wed, 10 Mar 2021 15:07:16 +0000 (09:07 -0600)
compiler/rustc_mir/src/lib.rs
compiler/rustc_mir/src/transform/coverage/graph.rs
library/core/src/option.rs

index bbfcec5a76a4352166d075b76c5bf0736a0f179f..93c17057590e60274694818f7ca4b516dfae9a91 100644 (file)
@@ -25,7 +25,7 @@
 #![feature(stmt_expr_attributes)]
 #![feature(trait_alias)]
 #![feature(option_expect_none)]
-#![feature(option_get_or_default)]
+#![feature(option_get_or_insert_default)]
 #![feature(or_patterns)]
 #![feature(once_cell)]
 #![feature(control_flow_enum)]
index 8ad0d133b17e142f90e671fe0a49b5756f0794a2..6f5fa858e25379bd9ad93a231cf2784da25a2e37 100644 (file)
@@ -392,7 +392,8 @@ pub fn set_edge_counter_from(
             }
         }
         let operand = counter_kind.as_operand_id();
-        if let Some(replaced) = self.edge_from_bcbs.get_or_default().insert(from_bcb, counter_kind)
+        if let Some(replaced) =
+            self.edge_from_bcbs.get_or_insert_default().insert(from_bcb, counter_kind)
         {
             Error::from_string(format!(
                 "attempt to set an edge counter more than once; from_bcb: \
index 9478e7f06bdf3a80885ebf2e42103bb0731afbcb..f1a0f455cd0918a8602984a012f00986b75c650b 100644 (file)
@@ -854,19 +854,17 @@ pub fn xor(self, optb: Option<T>) -> Option<T> {
     // Entry-like operations to insert if None and return a reference
     /////////////////////////////////////////////////////////////////////////
 
-    /// Inserts the default value into the option if it is [`None`], then
+    /// Inserts `value` into the option if it is [`None`], then
     /// returns a mutable reference to the contained value.
     ///
     /// # Examples
     ///
     /// ```
-    /// #![feature(option_get_or_default)]
-    ///
     /// let mut x = None;
     ///
     /// {
-    ///     let y: &mut u32 = x.get_or_default();
-    ///     assert_eq!(y, &0);
+    ///     let y: &mut u32 = x.get_or_insert(5);
+    ///     assert_eq!(y, &5);
     ///
     ///     *y = 7;
     /// }
@@ -874,25 +872,24 @@ pub fn xor(self, optb: Option<T>) -> Option<T> {
     /// assert_eq!(x, Some(7));
     /// ```
     #[inline]
-    #[unstable(feature = "option_get_or_default", issue = "82901")]
-    pub fn get_or_default(&mut self) -> &mut T
-    where
-        T: Default,
-    {
-        self.get_or_insert_with(Default::default)
+    #[stable(feature = "option_entry", since = "1.20.0")]
+    pub fn get_or_insert(&mut self, value: T) -> &mut T {
+        self.get_or_insert_with(|| value)
     }
 
-    /// Inserts `value` into the option if it is [`None`], then
+    /// Inserts the default value into the option if it is [`None`], then
     /// returns a mutable reference to the contained value.
     ///
     /// # Examples
     ///
     /// ```
+    /// #![feature(option_get_or_insert_default)]
+    ///
     /// let mut x = None;
     ///
     /// {
-    ///     let y: &mut u32 = x.get_or_insert(5);
-    ///     assert_eq!(y, &5);
+    ///     let y: &mut u32 = x.get_or_insert_default();
+    ///     assert_eq!(y, &0);
     ///
     ///     *y = 7;
     /// }
@@ -900,9 +897,12 @@ pub fn get_or_default(&mut self) -> &mut T
     /// assert_eq!(x, Some(7));
     /// ```
     #[inline]
-    #[stable(feature = "option_entry", since = "1.20.0")]
-    pub fn get_or_insert(&mut self, value: T) -> &mut T {
-        self.get_or_insert_with(|| value)
+    #[unstable(feature = "option_get_or_insert_default", issue = "82901")]
+    pub fn get_or_insert_default(&mut self) -> &mut T
+    where
+        T: Default,
+    {
+        self.get_or_insert_with(Default::default)
     }
 
     /// Inserts a value computed from `f` into the option if it is [`None`],