Rollup merge of #90269 - woppopo:const_option_expect, r=yaahc
Make `Option::expect` unstably const Tracking issue: #67441
This commit is contained in:
commit
94cd0259f2
1 changed files with 3 additions and 2 deletions
|
@ -703,7 +703,8 @@ impl<T> Option<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[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 {
|
match self {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => expect_failed(msg),
|
None => expect_failed(msg),
|
||||||
|
@ -1658,7 +1659,7 @@ impl<T, E> Option<Result<T, E>> {
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
#[cold]
|
#[cold]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
fn expect_failed(msg: &str) -> ! {
|
const fn expect_failed(msg: &str) -> ! {
|
||||||
panic!("{}", msg)
|
panic!("{}", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue