diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-10-17 07:52:21 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-17 07:52:21 +0900 |
| commit | 0029af7930de4fc46c9cd01d0a5b5fa8dd4a4b5d (patch) | |
| tree | 13a2981fcc3c5bf3c1a6f62f2e0ffd7544a8953b | |
| parent | b8173c59c67b6ad5d3215d1c617ee94f3e92cad1 (diff) | |
| parent | d1f7608699e07e345caf4188ecbf415914c3241b (diff) | |
| download | rust-0029af7930de4fc46c9cd01d0a5b5fa8dd4a4b5d.tar.gz rust-0029af7930de4fc46c9cd01d0a5b5fa8dd4a4b5d.zip | |
Rollup merge of #89953 - woppopo:option_const_as_mut, r=oli-obk
Make Option::as_mut const Adding `const` for `Option::as_mut`. Tracking issue: #67441
| -rw-r--r-- | library/core/src/option.rs | 3 | ||||
| -rw-r--r-- | library/core/tests/lib.rs | 1 | ||||
| -rw-r--r-- | library/core/tests/option.rs | 8 |
3 files changed, 11 insertions, 1 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 401267f5613..88505832158 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -646,7 +646,8 @@ impl<T> 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, diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 3608853dce4..cf669163d3e 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)] diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index 8995f96b123..c9508c14525 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] |
