Split out option::unwrap_failed
like we have result::unwrap_failed
...and like `option::expect_failed`
This commit is contained in:
parent
62d7ed4a67
commit
23483664a2
@ -921,14 +921,14 @@ pub const fn expect(self, msg: &str) -> T {
|
||||
/// let x: Option<&str> = None;
|
||||
/// assert_eq!(x.unwrap(), "air"); // fails
|
||||
/// ```
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
#[track_caller]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
|
||||
pub const fn unwrap(self) -> T {
|
||||
match self {
|
||||
Some(val) => val,
|
||||
None => panic("called `Option::unwrap()` on a `None` value"),
|
||||
None => unwrap_failed(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -1970,6 +1970,14 @@ pub const fn transpose(self) -> Result<Option<T>, E> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
|
||||
#[cfg_attr(feature = "panic_immediate_abort", inline)]
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
const fn unwrap_failed() -> ! {
|
||||
panic("called `Option::unwrap()` on a `None` value")
|
||||
}
|
||||
|
||||
// This is a separate function to reduce the code size of .expect() itself.
|
||||
#[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
|
||||
#[cfg_attr(feature = "panic_immediate_abort", inline)]
|
||||
|
@ -4,9 +4,9 @@
|
||||
// can correctly merge the debug info if it merges the inlined code (e.g., for merging of tail
|
||||
// calls to panic.
|
||||
|
||||
// CHECK: tail call void @_ZN4core9panicking5panic17h{{([0-9a-z]{16})}}E
|
||||
// CHECK: tail call void @_ZN4core6option13unwrap_failed17h{{([0-9a-z]{16})}}E
|
||||
// CHECK-SAME: !dbg ![[#first_dbg:]]
|
||||
// CHECK: tail call void @_ZN4core9panicking5panic17h{{([0-9a-z]{16})}}E
|
||||
// CHECK: tail call void @_ZN4core6option13unwrap_failed17h{{([0-9a-z]{16})}}E
|
||||
// CHECK-SAME: !dbg ![[#second_dbg:]]
|
||||
|
||||
// CHECK-DAG: ![[#func_dbg:]] = distinct !DISubprogram(name: "unwrap<i32>"
|
||||
|
@ -51,7 +51,7 @@ fn num_to_digit(_1: char) -> u32 {
|
||||
}
|
||||
|
||||
bb4: {
|
||||
_7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
|
||||
_7 = option::unwrap_failed() -> unwind unreachable;
|
||||
}
|
||||
|
||||
bb5: {
|
||||
|
@ -51,7 +51,7 @@ fn num_to_digit(_1: char) -> u32 {
|
||||
}
|
||||
|
||||
bb4: {
|
||||
_7 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
|
||||
_7 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb5: {
|
||||
|
@ -62,7 +62,7 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
|
||||
_11 = option::unwrap_failed() -> unwind unreachable;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
|
@ -60,7 +60,7 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
|
||||
_11 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
|
@ -62,7 +62,7 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
|
||||
_11 = option::unwrap_failed() -> unwind unreachable;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
|
@ -60,7 +60,7 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
|
||||
_11 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
|
Loading…
Reference in New Issue
Block a user