Add separate impl of unwrap_failed to avoid constructing trait objects
This commit is contained in:
parent
0adee2c01e
commit
917dafc73a
@ -1653,6 +1653,7 @@ pub const fn into_ok_or_err(self) -> T {
|
||||
}
|
||||
|
||||
// This is a separate function to reduce the code size of the methods
|
||||
#[cfg(not(feature = "panic_immediate_abort"))]
|
||||
#[inline(never)]
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
@ -1660,6 +1661,18 @@ fn unwrap_failed(msg: &str, error: &dyn fmt::Debug) -> ! {
|
||||
panic!("{}: {:?}", msg, error)
|
||||
}
|
||||
|
||||
// This is a separate function to avoid constructing a `dyn Debug`
|
||||
// that gets immediately thrown away, since vtables don't get cleaned up
|
||||
// by dead code elimination if a trait object is constructed even if it goes
|
||||
// unused
|
||||
#[cfg(feature = "panic_immediate_abort")]
|
||||
#[inline]
|
||||
#[cold]
|
||||
#[track_caller]
|
||||
fn unwrap_failed<T>(_msg: &str, _error: &T) -> ! {
|
||||
panic!()
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Trait implementations
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user