From aa6c83d3bb9ae4121bd6bf281b2f78d93f0c2615 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 8 Apr 2021 19:38:02 -0700 Subject: [PATCH] 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::() == target { 745 | | let unerased = e.cast::>>().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::>>().deref(); 745 | if TypeId::of::() == target { | warning: all if blocks contain the same code at the start --> src/error.rs:761:5 | 761 | / if TypeId::of::() == target { 762 | | let unerased = e.cast::>>().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::>>().deref_mut(); 762 | if TypeId::of::() == target { | --- src/error.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index f4f5bc2..92bb63d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -741,12 +741,11 @@ unsafe fn context_chain_downcast(e: Ref, target: TypeId) -> Option where C: 'static, { + let unerased = e.cast::>>().deref(); if TypeId::of::() == target { - let unerased = e.cast::>>().deref(); Some(Ref::new(&unerased._object.context).cast::<()>()) } else { // Recurse down the context chain per the inner error's vtable. - let unerased = e.cast::>>().deref(); let source = &unerased._object.error; (vtable(source.inner.ptr).object_downcast)(source.inner.by_ref(), target) } @@ -758,12 +757,11 @@ unsafe fn context_chain_downcast_mut(e: Mut, target: TypeId) -> Op where C: 'static, { + let unerased = e.cast::>>().deref_mut(); if TypeId::of::() == target { - let unerased = e.cast::>>().deref_mut(); Some(Mut::new(&mut unerased._object.context).cast::<()>()) } else { // Recurse down the context chain per the inner error's vtable. - let unerased = e.cast::>>().deref_mut(); let source = &mut unerased._object.error; (vtable(source.inner.ptr).object_downcast_mut)(source.inner.by_mut(), target) }