From 4c8d0acde6de6880d295cfcc5cf18c9c4a32adf7 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 11 Jun 2018 16:23:08 +0300 Subject: [PATCH 1/2] don't allocate via format! in case there's no error --- ethcore/src/views/view_rlp.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ethcore/src/views/view_rlp.rs b/ethcore/src/views/view_rlp.rs index 2ecc4dbdd3d..192ab0fa84e 100644 --- a/ethcore/src/views/view_rlp.rs +++ b/ethcore/src/views/view_rlp.rs @@ -39,10 +39,10 @@ impl<'a, 'view> ViewRlp<'a> where 'a : 'view { /// Returns a new instance replacing existing rlp with new rlp, maintaining debug info fn new_from_rlp(&self, rlp: Rlp<'a>) -> Self { - ViewRlp { - rlp, + ViewRlp { + rlp, file: self.file, - line: self.line + line: self.line } } @@ -53,7 +53,11 @@ impl<'a, 'view> ViewRlp<'a> where 'a : 'view { } fn expect_valid_rlp(&self, r: Result) -> T { - r.expect(&format!("View rlp is trusted and should be valid. Constructed in {} on line {}", self.file, self.line)) + r.unwrap_or_else(|_| panic!( + "View rlp is trusted and should be valid. Constructed in {} on line {}", + self.file, + self.line + )) } /// Returns rlp at the given index, panics if no rlp at that index @@ -75,7 +79,7 @@ impl<'a, 'view> ViewRlp<'a> where 'a : 'view { /// Returns decoded value at the given index, panics not present or valid at that index pub fn val_at(&self, index: usize) -> T where T : Decodable { self.expect_valid_rlp(self.rlp.val_at(index)) - } + } /// Returns decoded list of values, panics if rlp is invalid pub fn list_at(&self, index: usize) -> Vec where T: Decodable { From d00d800ca78100c81bec716c89c5f9c987a04805 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 11 Jun 2018 17:28:21 +0300 Subject: [PATCH 2/2] fix test? --- ethcore/src/views/view_rlp.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ethcore/src/views/view_rlp.rs b/ethcore/src/views/view_rlp.rs index 192ab0fa84e..2dd1b33a946 100644 --- a/ethcore/src/views/view_rlp.rs +++ b/ethcore/src/views/view_rlp.rs @@ -53,10 +53,11 @@ impl<'a, 'view> ViewRlp<'a> where 'a : 'view { } fn expect_valid_rlp(&self, r: Result) -> T { - r.unwrap_or_else(|_| panic!( - "View rlp is trusted and should be valid. Constructed in {} on line {}", + r.unwrap_or_else(|e| panic!( + "View rlp is trusted and should be valid. Constructed in {} on line {}: {}", self.file, - self.line + self.line, + e )) }