Use unwrap instead of unwrap_unchecked
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
@@ -844,9 +844,13 @@ impl Error {
|
|||||||
ErrorData::Custom(b) if b.error.is::<E>() => {
|
ErrorData::Custom(b) if b.error.is::<E>() => {
|
||||||
let res = (*b).error.downcast::<E>();
|
let res = (*b).error.downcast::<E>();
|
||||||
|
|
||||||
// Safety: b.error.is::<E>() returns true,
|
// downcast is a really trivial and is marked as inline, so
|
||||||
// which means that res must be Ok(e).
|
// it's likely be inlined here.
|
||||||
Ok(unsafe { res.unwrap_unchecked() })
|
//
|
||||||
|
// And the compiler should be able to eliminate the branch
|
||||||
|
// that produces `Err` here since b.error.is::<E>()
|
||||||
|
// returns true.
|
||||||
|
Ok(res.unwrap())
|
||||||
}
|
}
|
||||||
repr_data => Err(Self { repr: Repr::new(repr_data) }),
|
repr_data => Err(Self { repr: Repr::new(repr_data) }),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user