Skip to content

Commit

Permalink
Rollup merge of rust-lang#90269 - woppopo:const_option_expect, r=yaahc
Browse files Browse the repository at this point in the history
Make `Option::expect` unstably const

Tracking issue: rust-lang#67441
  • Loading branch information
matthiaskrgr authored Dec 3, 2021
2 parents 31003a3 + 7430b22 commit 94cd025
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -1658,7 +1659,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)
}

Expand Down

0 comments on commit 94cd025

Please sign in to comment.