Skip to content

Commit aa6c83d

Browse files
committed
Resolve branches_sharing_code clippy lint
warning: all if blocks contain the same code at the start --> src/error.rs:744:5 | 744 | / if TypeId::of::<C>() == target { 745 | | let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref(); | |_____________________________________________________________________________^ | = note: `#[warn(clippy::branches_sharing_code)]` on by default = warning: Some moved values might need to be renamed to avoid wrong references = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code help: consider moving the start statements out like this | 744 | let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref(); 745 | if TypeId::of::<C>() == target { | warning: all if blocks contain the same code at the start --> src/error.rs:761:5 | 761 | / if TypeId::of::<C>() == target { 762 | | let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut(); | |_________________________________________________________________________________^ | = warning: Some moved values might need to be renamed to avoid wrong references = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#branches_sharing_code help: consider moving the start statements out like this | 761 | let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut(); 762 | if TypeId::of::<C>() == target { |
1 parent 704622f commit aa6c83d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -741,12 +741,11 @@ unsafe fn context_chain_downcast<C>(e: Ref<ErrorImpl>, target: TypeId) -> Option
741741
where
742742
C: 'static,
743743
{
744+
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
744745
if TypeId::of::<C>() == target {
745-
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
746746
Some(Ref::new(&unerased._object.context).cast::<()>())
747747
} else {
748748
// Recurse down the context chain per the inner error's vtable.
749-
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();
750749
let source = &unerased._object.error;
751750
(vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target)
752751
}
@@ -758,12 +757,11 @@ unsafe fn context_chain_downcast_mut<C>(e: Mut<ErrorImpl>, target: TypeId) -> Op
758757
where
759758
C: 'static,
760759
{
760+
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
761761
if TypeId::of::<C>() == target {
762-
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
763762
Some(Mut::new(&mut unerased._object.context).cast::<()>())
764763
} else {
765764
// Recurse down the context chain per the inner error's vtable.
766-
let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();
767765
let source = &mut unerased._object.error;
768766
(vtable(source.inner.ptr).object_downcast_mut)(source.inner.by_mut(), target)
769767
}

0 commit comments

Comments
 (0)