Skip to content
Myr

Resolve branches_sharing_code clippy lint

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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 { |

authored by David Tolnay · committed by David Tolnay · parent 704622f · Browse files · 1 file+2 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+2 added−4 removed

  • other:+2 added−4 removed

1 file+2 added−4 removed

modified:src/error.rs+2 added-4 removed
739 unmodified lines
740unsafe fn context_chain_downcast<C>(e: Ref<ErrorImpl>, target: TypeId) -> Option<Ref<()>>741where742 C: 'static,743{744 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();745 if TypeId::of::<C>() == target {745 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();746 Some(Ref::new(&unerased._object.context).cast::<()>())747 } else {748 // Recurse down the context chain per the inner error's vtable.749 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref();749 let source = &unerased._object.error;750 (vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target)751 }752}
3 unmodified lines
756unsafe fn context_chain_downcast_mut<C>(e: Mut<ErrorImpl>, target: TypeId) -> Option<Mut<()>>757where758 C: 'static,759{760 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();761 if TypeId::of::<C>() == target {762 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();762 Some(Mut::new(&mut unerased._object.context).cast::<()>())763 } else {764 // Recurse down the context chain per the inner error's vtable.766 let unerased = e.cast::<ErrorImpl<ContextError<C, Error>>>().deref_mut();765 let source = &mut unerased._object.error;766 (vtable(source.inner.ptr).object_downcast_mut)(source.inner.by_mut(), target)767 }768}
186 unmodified lines