Make Option::as_mut const
This commit is contained in:
@@ -646,7 +646,8 @@ impl<T> Option<T> {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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 {
|
match *self {
|
||||||
Some(ref mut x) => Some(x),
|
Some(ref mut x) => Some(x),
|
||||||
None => None,
|
None => None,
|
||||||
|
|||||||
@@ -380,6 +380,14 @@ const fn option_const_mut() {
|
|||||||
|
|
||||||
let _take = option.take();
|
let _take = option.take();
|
||||||
let _replace = option.replace(42);
|
let _replace = option.replace(42);
|
||||||
|
|
||||||
|
{
|
||||||
|
let as_mut = option.as_mut();
|
||||||
|
match as_mut {
|
||||||
|
Some(v) => *v = 32,
|
||||||
|
None => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user