Skip to content

Commit

Permalink
Rollup merge of #89953 - woppopo:option_const_as_mut, r=oli-obk
Browse files Browse the repository at this point in the history
Make Option::as_mut const

Adding `const` for `Option::as_mut`.

Tracking issue: #67441
  • Loading branch information
JohnTitor committed Oct 16, 2021
2 parents b8173c5 + d1f7608 commit 0029af7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 8 additions & 0 deletions library/core/tests/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 0029af7

Please sign in to comment.