explicitly ignores struct fields which do not impact PartialEq impl (#24624)
Unless struct fields are explicitly ignored in PartialEq implementation, there are no compile-time checks that if more fields are added to the struct, PartialEq implementation is accordingly updated.
This commit is contained in:
parent
8a062273de
commit
be0bdd2261
|
@ -155,7 +155,6 @@ use {
|
||||||
fmt, mem,
|
fmt, mem,
|
||||||
ops::{Deref, Div, RangeInclusive},
|
ops::{Deref, Div, RangeInclusive},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
ptr,
|
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{
|
atomic::{
|
||||||
|
@ -993,39 +992,101 @@ pub(crate) struct BankFieldsToSerialize<'a> {
|
||||||
// Can't derive PartialEq because RwLock doesn't implement PartialEq
|
// Can't derive PartialEq because RwLock doesn't implement PartialEq
|
||||||
impl PartialEq for Bank {
|
impl PartialEq for Bank {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
if ptr::eq(self, other) {
|
if std::ptr::eq(self, other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
*self.blockhash_queue.read().unwrap() == *other.blockhash_queue.read().unwrap()
|
let Self {
|
||||||
&& self.ancestors == other.ancestors
|
rc: _,
|
||||||
&& *self.hash.read().unwrap() == *other.hash.read().unwrap()
|
src: _,
|
||||||
&& self.parent_hash == other.parent_hash
|
blockhash_queue,
|
||||||
&& self.parent_slot == other.parent_slot
|
ancestors,
|
||||||
&& *self.hard_forks.read().unwrap() == *other.hard_forks.read().unwrap()
|
hash,
|
||||||
&& self.transaction_count.load(Relaxed) == other.transaction_count.load(Relaxed)
|
parent_hash,
|
||||||
&& self.tick_height.load(Relaxed) == other.tick_height.load(Relaxed)
|
parent_slot,
|
||||||
&& self.signature_count.load(Relaxed) == other.signature_count.load(Relaxed)
|
hard_forks,
|
||||||
&& self.capitalization.load(Relaxed) == other.capitalization.load(Relaxed)
|
transaction_count,
|
||||||
&& self.max_tick_height == other.max_tick_height
|
transaction_error_count: _,
|
||||||
&& self.hashes_per_tick == other.hashes_per_tick
|
transaction_entries_count: _,
|
||||||
&& self.ticks_per_slot == other.ticks_per_slot
|
transactions_per_entry_max: _,
|
||||||
&& self.ns_per_slot == other.ns_per_slot
|
tick_height,
|
||||||
&& self.genesis_creation_time == other.genesis_creation_time
|
signature_count,
|
||||||
&& self.slots_per_year == other.slots_per_year
|
capitalization,
|
||||||
&& self.slot == other.slot
|
max_tick_height,
|
||||||
&& self.epoch == other.epoch
|
hashes_per_tick,
|
||||||
&& self.block_height == other.block_height
|
ticks_per_slot,
|
||||||
&& self.collector_id == other.collector_id
|
ns_per_slot,
|
||||||
&& self.collector_fees.load(Relaxed) == other.collector_fees.load(Relaxed)
|
genesis_creation_time,
|
||||||
&& self.fee_calculator == other.fee_calculator
|
slots_per_year,
|
||||||
&& self.fee_rate_governor == other.fee_rate_governor
|
slot,
|
||||||
&& self.collected_rent.load(Relaxed) == other.collected_rent.load(Relaxed)
|
bank_id: _,
|
||||||
&& self.rent_collector == other.rent_collector
|
epoch,
|
||||||
&& self.epoch_schedule == other.epoch_schedule
|
block_height,
|
||||||
&& *self.inflation.read().unwrap() == *other.inflation.read().unwrap()
|
collector_id,
|
||||||
&& *self.stakes_cache.stakes() == *other.stakes_cache.stakes()
|
collector_fees,
|
||||||
&& self.epoch_stakes == other.epoch_stakes
|
fee_calculator,
|
||||||
&& self.is_delta.load(Relaxed) == other.is_delta.load(Relaxed)
|
fee_rate_governor,
|
||||||
|
collected_rent,
|
||||||
|
rent_collector,
|
||||||
|
epoch_schedule,
|
||||||
|
inflation,
|
||||||
|
stakes_cache,
|
||||||
|
epoch_stakes,
|
||||||
|
is_delta,
|
||||||
|
// TODO: Confirm if all these fields are intentionally ignored!
|
||||||
|
builtin_programs: _,
|
||||||
|
compute_budget: _,
|
||||||
|
builtin_feature_transitions: _,
|
||||||
|
rewards: _,
|
||||||
|
cluster_type: _,
|
||||||
|
lazy_rent_collection: _,
|
||||||
|
rewards_pool_pubkeys: _,
|
||||||
|
cached_executors: _,
|
||||||
|
transaction_debug_keys: _,
|
||||||
|
transaction_log_collector_config: _,
|
||||||
|
transaction_log_collector: _,
|
||||||
|
feature_set: _,
|
||||||
|
drop_callback: _,
|
||||||
|
freeze_started: _,
|
||||||
|
vote_only_bank: _,
|
||||||
|
cost_tracker: _,
|
||||||
|
rewrites_skipped_this_slot: _,
|
||||||
|
sysvar_cache: _,
|
||||||
|
accounts_data_len: _,
|
||||||
|
fee_structure: _,
|
||||||
|
// Ignore new fields explicitly if they do not impact PartialEq.
|
||||||
|
// Adding ".." will remove compile-time checks that if a new field
|
||||||
|
// is added to the struct, this ParitalEq is accordingly updated.
|
||||||
|
} = self;
|
||||||
|
*blockhash_queue.read().unwrap() == *other.blockhash_queue.read().unwrap()
|
||||||
|
&& ancestors == &other.ancestors
|
||||||
|
&& *hash.read().unwrap() == *other.hash.read().unwrap()
|
||||||
|
&& parent_hash == &other.parent_hash
|
||||||
|
&& parent_slot == &other.parent_slot
|
||||||
|
&& *hard_forks.read().unwrap() == *other.hard_forks.read().unwrap()
|
||||||
|
&& transaction_count.load(Relaxed) == other.transaction_count.load(Relaxed)
|
||||||
|
&& tick_height.load(Relaxed) == other.tick_height.load(Relaxed)
|
||||||
|
&& signature_count.load(Relaxed) == other.signature_count.load(Relaxed)
|
||||||
|
&& capitalization.load(Relaxed) == other.capitalization.load(Relaxed)
|
||||||
|
&& max_tick_height == &other.max_tick_height
|
||||||
|
&& hashes_per_tick == &other.hashes_per_tick
|
||||||
|
&& ticks_per_slot == &other.ticks_per_slot
|
||||||
|
&& ns_per_slot == &other.ns_per_slot
|
||||||
|
&& genesis_creation_time == &other.genesis_creation_time
|
||||||
|
&& slots_per_year == &other.slots_per_year
|
||||||
|
&& slot == &other.slot
|
||||||
|
&& epoch == &other.epoch
|
||||||
|
&& block_height == &other.block_height
|
||||||
|
&& collector_id == &other.collector_id
|
||||||
|
&& collector_fees.load(Relaxed) == other.collector_fees.load(Relaxed)
|
||||||
|
&& fee_calculator == &other.fee_calculator
|
||||||
|
&& fee_rate_governor == &other.fee_rate_governor
|
||||||
|
&& collected_rent.load(Relaxed) == other.collected_rent.load(Relaxed)
|
||||||
|
&& rent_collector == &other.rent_collector
|
||||||
|
&& epoch_schedule == &other.epoch_schedule
|
||||||
|
&& *inflation.read().unwrap() == *other.inflation.read().unwrap()
|
||||||
|
&& *stakes_cache.stakes() == *other.stakes_cache.stakes()
|
||||||
|
&& epoch_stakes == &other.epoch_stakes
|
||||||
|
&& is_delta.load(Relaxed) == other.is_delta.load(Relaxed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,12 @@ impl Default for VoteAccountInner {
|
||||||
|
|
||||||
impl PartialEq<VoteAccountInner> for VoteAccountInner {
|
impl PartialEq<VoteAccountInner> for VoteAccountInner {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.account == other.account
|
let Self {
|
||||||
|
account,
|
||||||
|
vote_state: _,
|
||||||
|
vote_state_once: _,
|
||||||
|
} = self;
|
||||||
|
account == &other.account
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +286,12 @@ impl Clone for VoteAccounts {
|
||||||
|
|
||||||
impl PartialEq<VoteAccounts> for VoteAccounts {
|
impl PartialEq<VoteAccounts> for VoteAccounts {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.vote_accounts == other.vote_accounts
|
let Self {
|
||||||
|
vote_accounts,
|
||||||
|
staked_nodes: _,
|
||||||
|
staked_nodes_once: _,
|
||||||
|
} = self;
|
||||||
|
vote_accounts == &other.vote_accounts
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue