Skip to content

Commit 0029af7

Browse files
authored
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
2 parents b8173c5 + d1f7608 commit 0029af7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

library/core/src/option.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,8 @@ impl<T> Option<T> {
646646
/// ```
647647
#[inline]
648648
#[stable(feature = "rust1", since = "1.0.0")]
649-
pub fn as_mut(&mut self) -> Option<&mut T> {
649+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
650+
pub const fn as_mut(&mut self) -> Option<&mut T> {
650651
match *self {
651652
Some(ref mut x) => Some(x),
652653
None => None,

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(const_assume)]
1111
#![feature(const_cell_into_inner)]
1212
#![feature(const_maybe_uninit_assume_init)]
13+
#![cfg_attr(bootstrap, feature(const_panic))]
1314
#![feature(const_ptr_read)]
1415
#![feature(const_ptr_write)]
1516
#![feature(const_ptr_offset)]

library/core/tests/option.rs

+8
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ const fn option_const_mut() {
380380

381381
let _take = option.take();
382382
let _replace = option.replace(42);
383+
384+
{
385+
let as_mut = option.as_mut();
386+
match as_mut {
387+
Some(v) => *v = 32,
388+
None => unreachable!(),
389+
}
390+
}
383391
}
384392

385393
#[test]

0 commit comments

Comments
 (0)