Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clippy): Resolve some lifetime and reference lints #4578

Merged
merged 4 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion zebra-chain/src/orchard/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ impl NoteCommitmentTree {
.cached_root
.write()
.expect("a thread that previously held exclusive lock access panicked");
match *write_root {
let read_root = write_root.as_ref().cloned();
match read_root {
// Another thread got write access first, return cached root.
Some(root) => root,
None => {
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/sapling/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ impl NoteCommitmentTree {
.cached_root
.write()
.expect("a thread that previously held exclusive lock access panicked");
match *write_root {
let read_root = write_root.as_ref().cloned();
match read_root {
// Another thread got write access first, return cached root.
Some(root) => root,
None => {
Expand Down
3 changes: 2 additions & 1 deletion zebra-chain/src/sprout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ impl NoteCommitmentTree {
.cached_root
.write()
.expect("a thread that previously held exclusive lock access panicked");
match *write_root {
let read_root = write_root.as_ref().cloned();
match read_root {
// Another thread got write access first, return cached root.
Some(root) => root,
None => {
Expand Down
2 changes: 1 addition & 1 deletion zebra-chain/src/transparent/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) fn parse_coinbase_height(
mut data: Vec<u8>,
) -> Result<(block::Height, CoinbaseData), SerializationError> {
use block::Height;
match (data.get(0), data.len()) {
match (data.first(), data.len()) {
teor2345 marked this conversation as resolved.
Show resolved Hide resolved
// Blocks 1 through 16 inclusive encode block height with OP_N opcodes.
(Some(op_n @ 0x51..=0x60), len) if len >= 1 => Ok((
Height((op_n - 0x50) as u32),
Expand Down
12 changes: 9 additions & 3 deletions zebra-state/src/service/chain_tip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,18 @@ impl ChainTipSender {
// a read-lock being created and living beyond the `self.sender.send(..)` call. If that
// happens, the `send` method will attempt to obtain a write-lock and will dead-lock.
// Without the binding, the guard is dropped at the end of the expression.
let needs_update = match (new_tip.as_ref(), self.sender.borrow().as_ref()) {
let active_hash = self
.sender
.borrow()
.as_ref()
.map(|active_value| active_value.hash);

let needs_update = match (new_tip.as_ref(), active_hash) {
// since the blocks have been contextually validated,
// we know their hashes cover all the block data
(Some(new_tip), Some(active_value)) => new_tip.hash != active_value.hash,
(Some(new_tip), Some(active_hash)) => new_tip.hash != active_hash,
(Some(_new_tip), None) => true,
(None, _active_value) => false,
(None, _active_value_hash) => false,
};

if needs_update {
Expand Down
2 changes: 1 addition & 1 deletion zebra-state/src/service/finalized_state/disk_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ where
type Bytes = T::Bytes;

fn as_bytes(&self) -> Self::Bytes {
T::as_bytes(&*self)
T::as_bytes(self)
}
}

Expand Down