Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,19 +950,19 @@ impl Error {
where
E: error::Error + Send + Sync + 'static,
{
match self.repr.into_data() {
ErrorData::Custom(b) if b.error.is::<E>() => {
let res = (*b).error.downcast::<E>();

// downcast is a really trivial and is marked as inline, so
// it's likely be inlined here.
//
// And the compiler should be able to eliminate the branch
// that produces `Err` here since b.error.is::<E>()
// returns true.
Ok(*res.unwrap())
if let ErrorData::Custom(c) = self.repr.data()
&& c.error.is::<E>()
{
if let ErrorData::Custom(b) = self.repr.into_data()
&& let Ok(err) = b.error.downcast::<E>()
{
Ok(*err)
} else {
// Safety: We have just checked that the condition is true
unsafe { crate::hint::unreachable_unchecked() }
}
repr_data => Err(Self { repr: Repr::new(repr_data) }),
} else {
Err(self)
}
}

Expand Down
9 changes: 0 additions & 9 deletions library/std/src/io/error/repr_bitpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ unsafe impl Send for Repr {}
unsafe impl Sync for Repr {}

impl Repr {
pub(super) fn new(dat: ErrorData<Box<Custom>>) -> Self {
match dat {
ErrorData::Os(code) => Self::new_os(code),
ErrorData::Simple(kind) => Self::new_simple(kind),
ErrorData::SimpleMessage(simple_message) => Self::new_simple_message(simple_message),
ErrorData::Custom(b) => Self::new_custom(b),
}
}

pub(super) fn new_custom(b: Box<Custom>) -> Self {
let p = Box::into_raw(b).cast::<u8>();
// Should only be possible if an allocator handed out a pointer with
Expand Down
3 changes: 0 additions & 3 deletions library/std/src/io/error/repr_unpacked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub(super) struct Repr(Inner);

impl Repr {
#[inline]
pub(super) fn new(dat: ErrorData<Box<Custom>>) -> Self {
Self(dat)
}
pub(super) fn new_custom(b: Box<Custom>) -> Self {
Self(Inner::Custom(b))
}
Expand Down
Loading