Make Option::expect
const
This commit is contained in:
parent
235d9853d8
commit
7430b22b5f
1 changed files with 3 additions and 2 deletions
|
@ -703,7 +703,8 @@ impl<T> Option<T> {
|
|||
#[inline]
|
||||
#[track_caller]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn expect(self, msg: &str) -> T {
|
||||
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
|
||||
pub const fn expect(self, msg: &str) -> T {
|
||||
match self {
|
||||
Some(val) => val,
|
||||
None => expect_failed(msg),
|
||||
|
@ -1634,7 +1635,7 @@ impl<T, E> Option<Result<T, E>> {
|
|||
#[inline(never)]
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
fn expect_failed(msg: &str) -> ! {
|
||||
const fn expect_failed(msg: &str) -> ! {
|
||||
panic!("{}", msg)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue