mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #119954 - scottmcm:option-unwrap-failed, r=WaffleLapkin
Split out `option::unwrap_failed` like we have `result::unwrap_failed` ...and like `option::expect_failed`
This commit is contained in:
commit
bf2637f4e8
@ -921,14 +921,14 @@ impl<T> Option<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 @@ impl<T, E> Option<Result<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: {
|
||||
|
@ -64,7 +64,7 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
|
||||
_11 = option::unwrap_failed() -> unwind unreachable;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
|
@ -64,7 +64,7 @@
|
||||
}
|
||||
|
||||
bb2: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
|
||||
_11 = option::unwrap_failed() -> unwind continue;
|
||||
}
|
||||
|
||||
bb3: {
|
||||
|
@ -64,7 +64,7 @@
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
|
||||
_11 = option::unwrap_failed() -> unwind unreachable;
|
||||
}
|
||||
|
||||
bb2: {
|
||||
|
@ -64,7 +64,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