From 00dba3a6938fb996b5d3b7f67823fc5272b38f59 Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 17 Oct 2021 00:02:42 +0900 Subject: [PATCH 1/2] Make Option::as_mut const --- library/core/src/option.rs | 3 ++- library/core/tests/option.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 401267f5613ee..885058321589c 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -646,7 +646,8 @@ impl Option { /// ``` #[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, diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index 8995f96b1238a..c9508c145258c 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -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] From d1f7608699e07e345caf4188ecbf415914c3241b Mon Sep 17 00:00:00 2001 From: woppopo Date: Sun, 17 Oct 2021 00:32:01 +0900 Subject: [PATCH 2/2] Add `#![cfg_attr(bootstrap, feature(const_panic))]` to `library/core/tests/lib.rs` --- library/core/tests/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 3608853dce4e0..cf669163d3ef2 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -10,6 +10,7 @@ #![feature(const_assume)] #![feature(const_cell_into_inner)] #![feature(const_maybe_uninit_assume_init)] +#![cfg_attr(bootstrap, feature(const_panic))] #![feature(const_ptr_read)] #![feature(const_ptr_write)] #![feature(const_ptr_offset)]