Skip to content

Commit 7430b22

Browse files
committed
Make Option::expect const
1 parent 235d985 commit 7430b22

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/core/src/option.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ impl<T> Option<T> {
703703
#[inline]
704704
#[track_caller]
705705
#[stable(feature = "rust1", since = "1.0.0")]
706-
pub fn expect(self, msg: &str) -> T {
706+
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
707+
pub const fn expect(self, msg: &str) -> T {
707708
match self {
708709
Some(val) => val,
709710
None => expect_failed(msg),
@@ -1634,7 +1635,7 @@ impl<T, E> Option<Result<T, E>> {
16341635
#[inline(never)]
16351636
#[cold]
16361637
#[track_caller]
1637-
fn expect_failed(msg: &str) -> ! {
1638+
const fn expect_failed(msg: &str) -> ! {
16381639
panic!("{}", msg)
16391640
}
16401641

0 commit comments

Comments
 (0)