]> git.lizzy.rs Git - rust.git/commitdiff
Make Option::as_mut const
authorwoppopo <woppopo@protonmail.com>
Sat, 16 Oct 2021 15:02:42 +0000 (00:02 +0900)
committerwoppopo <woppopo@protonmail.com>
Sat, 16 Oct 2021 15:02:42 +0000 (00:02 +0900)
library/core/src/option.rs
library/core/tests/option.rs

index 401267f5613ee0c478ec470f4fa7496527004478..885058321589ccb6953146c252701a405a487986 100644 (file)
@@ -646,7 +646,8 @@ pub const fn as_ref(&self) -> Option<&T> {
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn as_mut(&mut self) -> Option<&mut T> {
+    #[rustc_const_unstable(feature = "const_option", issue = "67441")]
+    pub const fn as_mut(&mut self) -> Option<&mut T> {
         match *self {
             Some(ref mut x) => Some(x),
             None => None,
index 8995f96b1238a654badb66cece7ed962f109dd3c..c9508c145258c9e6340758579431e499b96210e8 100644 (file)
@@ -380,6 +380,14 @@ const fn option_const_mut() {
 
     let _take = option.take();
     let _replace = option.replace(42);
+
+    {
+        let as_mut = option.as_mut();
+        match as_mut {
+            Some(v) => *v = 32,
+            None => unreachable!(),
+        }
+    }
 }
 
 #[test]