Skip to content

Update rustfmt #427

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

Merged
merged 1 commit into from
Jul 18, 2018
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ language: rust
rust:
- stable
install:
- rustup toolchain install nightly-2018-05-07
- rustup component add rustfmt-preview --toolchain nightly-2018-05-07
- rustup toolchain install nightly-2018-07-17
- rustup component add rustfmt-preview --toolchain nightly-2018-07-17
before_script:
- cargo fetch --verbose
script:
- cargo +nightly-2018-05-07 fmt -- --write-mode=diff
- cargo +nightly-2018-07-17 fmt -- --check
- RUST_BACKTRACE=1 cargo test --verbose --all
matrix:
allow_failures:
Expand Down
10 changes: 6 additions & 4 deletions codechain/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@ fn run_node(matches: ArgMatches) -> Result<(), String> {
let config = load_config(&matches)?;
let spec = config.operating.chain.spec()?;

let instance_id = config.operating.instance_id.unwrap_or(SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Current time should be later than unix epoch")
.subsec_nanos() as usize);
let instance_id = config.operating.instance_id.unwrap_or(
SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Current time should be later than unix epoch")
.subsec_nanos() as usize,
);
clogger::init(&LoggerConfig::new(instance_id)).expect("Logger must be successfully initialized");

// FIXME: Handle IO error.
Expand Down
3 changes: 2 additions & 1 deletion core/src/blockchain/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ impl BlockInvoices {

impl Decodable for BlockInvoices {
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
let invoices = rlp.as_list::<Vec<u8>>()?
let invoices = rlp
.as_list::<Vec<u8>>()?
.iter()
.map(|parcel_invoice| UntrustedRlp::new(&parcel_invoice).as_val::<ParcelInvoice>())
.collect::<Result<Vec<_>, _>>()?;
Expand Down
6 changes: 1 addition & 5 deletions core/src/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,4 @@ pub trait CodeChainEngine: ConsensusEngine<CodeChainMachine> {
}

// convenience wrappers for existing functions.
impl<T> CodeChainEngine for T
where
T: ConsensusEngine<CodeChainMachine>,
{
}
impl<T> CodeChainEngine for T where T: ConsensusEngine<CodeChainMachine> {}
7 changes: 5 additions & 2 deletions core/src/consensus/tendermint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ impl Tendermint {

/// Broadcast all messages since last issued block to get the peers up to speed.
fn broadcast_old_messages(&self) {
for m in self.votes
for m in self
.votes
.get_up_to(&VoteStep::new(
self.height.load(AtomicOrdering::SeqCst),
self.view.load(AtomicOrdering::SeqCst),
Expand Down Expand Up @@ -359,7 +360,9 @@ impl Tendermint {
Some(lock) => vote_step > &lock.vote_step,
None => true,
};
let lock_change = is_newer_than_lock && vote_step.step == Step::Prevote && message.block_hash.is_some()
let lock_change = is_newer_than_lock
&& vote_step.step == Step::Prevote
&& message.block_hash.is_some()
&& self.has_enough_aligned_votes(message);
if lock_change {
ctrace!(ENGINE, "handle_valid_message: Lock change.");
Expand Down
3 changes: 2 additions & 1 deletion core/src/miner/local_parcels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ impl LocalParcelsList {
return
}

let to_remove = self.parcels
let to_remove = self
.parcels
.iter()
.filter(|&(_, status)| !status.is_current())
.map(|(hash, _)| *hash)
Expand Down
12 changes: 8 additions & 4 deletions core/src/miner/mem_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ impl ParcelSet {
};

Some(to_drop.into_iter().fold(HashMap::new(), |mut removed, (sender, nonce)| {
let order = self.drop(&sender, &nonce)
let order = self
.drop(&sender, &nonce)
.expect("Parcel has just been found in `by_priority`; so it is in `by_address` also.");
ctrace!(MEM_POOL, "Dropped out of limit parcel: {:?}", order.hash);

Expand Down Expand Up @@ -469,7 +470,8 @@ impl MemPool {
pub fn remove_old<F>(&mut self, fetch_account: &F, current_time: PoolingInstant)
where
F: Fn(&Address) -> AccountDetails, {
let senders = self.current
let senders = self
.current
.by_address
.keys()
.chain(self.future.by_address.keys())
Expand All @@ -483,7 +485,8 @@ impl MemPool {
let max_time = self.max_time_in_pool;
let balance_check = max_time >> 3;
// Clear parcels occupying the pool too long
let invalid = self.by_hash
let invalid = self
.by_hash
.iter()
.filter(|&(_, ref parcel)| !parcel.origin.is_local())
.map(|(hash, parcel)| (hash, parcel, current_time.saturating_sub(parcel.insertion_time)))
Expand Down Expand Up @@ -931,7 +934,8 @@ impl MemPool {
fn mark_parcels_local(&mut self, sender: &Address) {
fn mark_local<F: FnMut(H256)>(sender: &Address, set: &mut ParcelSet, mut mark: F) {
// Mark all parcels from this sender as local
let nonces_from_sender = set.by_address
let nonces_from_sender = set
.by_address
.row(sender)
.map(|row_map| {
row_map
Expand Down
15 changes: 10 additions & 5 deletions core/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ impl Miner {
if sealing_work.enabled {
ctrace!(MINER, "requires_reseal: sealing enabled");
let last_request = *self.sealing_block_last_request.lock();
let should_disable_sealing = !self.options.force_sealing && !has_local_parcels
let should_disable_sealing = !self.options.force_sealing
&& !has_local_parcels
&& self.engine.seals_internally().is_none()
&& best_block > last_request
&& best_block - last_request > SEALING_TIMEOUT_IN_BLOCKS;
Expand Down Expand Up @@ -209,7 +210,8 @@ impl Miner {
cdebug!(MINER, "Rejected parcel {:?}: already in the blockchain", hash);
return Err(Error::Parcel(ParcelError::AlreadyImported))
}
match self.engine
match self
.engine
.verify_parcel_basic(&parcel, &best_block_header)
.and_then(|_| self.engine.verify_parcel_unordered(parcel, &best_block_header))
{
Expand All @@ -221,7 +223,8 @@ impl Miner {
// This check goes here because verify_parcel takes SignedParcel parameter
self.engine.machine().verify_parcel(&parcel, &best_block_header, client)?;

let origin = self.accounts
let origin = self
.accounts
.as_ref()
.and_then(|accounts| match accounts.has_account(parcel.sender()) {
Ok(true) => Some(ParcelOrigin::Local),
Expand Down Expand Up @@ -419,7 +422,8 @@ impl Miner {
fn seal_and_import_block_internally<C>(&self, chain: &C, block: ClosedBlock) -> bool
where
C: BlockChain + ImportSealedBlock, {
if block.parcels().is_empty() && !self.options.force_sealing
if block.parcels().is_empty()
&& !self.options.force_sealing
&& Instant::now() <= *self.next_mandatory_reseal.read()
{
return false
Expand Down Expand Up @@ -701,7 +705,8 @@ impl MinerService for Miner {
// Be sure to release the lock before we call prepare_work_sealing
let mut mem_pool = self.mem_pool.write();
// We need to re-validate parcels
let import = self.add_parcels_to_pool(chain, vec![parcel.into()], ParcelOrigin::Local, &mut mem_pool)
let import = self
.add_parcels_to_pool(chain, vec![parcel.into()], ParcelOrigin::Local, &mut mem_pool)
.pop()
.expect("one result returned per added parcel; one added => one result; qed");

Expand Down
3 changes: 2 additions & 1 deletion core/src/miner/work_notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ pub struct WorkPoster {
impl WorkPoster {
/// Create new `WorkPoster`.
pub fn new(urls: &[String]) -> Self {
let urls = urls.into_iter()
let urls = urls
.into_iter()
.filter_map(|u| match Url::parse(u) {
Ok(url) => Some(url),
Err(e) => {
Expand Down
8 changes: 4 additions & 4 deletions core/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ impl ClientService {
db_config.compaction = config.db_compaction.compaction_profile(client_path);
db_config.wal = config.db_wal;

let db = Arc::new(Database::open(
&db_config,
&client_path.to_str().expect("DB path could not be converted to string."),
).map_err(::client::Error::Database)?);
let db = Arc::new(
Database::open(&db_config, &client_path.to_str().expect("DB path could not be converted to string."))
.map_err(::client::Error::Database)?,
);

let client = Client::new(config, &spec, db, miner, io_service.channel())?;

Expand Down
3 changes: 2 additions & 1 deletion core/src/state/shard_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ impl<B: Backend + ShardBackend> ShardStateInternal for ShardLevelState<B> {
let asset_type = input.prev_out.asset_type.clone();
let asset_scheme_address = AssetSchemeAddress::from_hash(asset_type)
.ok_or(TransactionError::AssetSchemeNotFound(asset_type.into()))?;
let _asset_scheme = self.asset_scheme((&asset_scheme_address).into())?
let _asset_scheme = self
.asset_scheme((&asset_scheme_address).into())?
.ok_or(TransactionError::AssetSchemeNotFound(asset_scheme_address.into()))?;

match self.asset(&address)? {
Expand Down
8 changes: 6 additions & 2 deletions core/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ impl StateDB {
pub fn new(db: Box<JournalDB>, cache_size: usize) -> StateDB {
assert_eq!(
100,
ACCOUNT_CACHE_RATIO + METADATA_CACHE_RATIO + SHARD_CACHE_RATIO + ASSET_SCHEME_CACHE_RATIO
ACCOUNT_CACHE_RATIO
+ METADATA_CACHE_RATIO
+ SHARD_CACHE_RATIO
+ ASSET_SCHEME_CACHE_RATIO
+ ASSET_CACHE_RATIO
);

Expand Down Expand Up @@ -411,7 +414,8 @@ impl StateDB {
/// Heap size used.
pub fn mem_used(&self) -> usize {
// TODO: account for LRU-cache overhead; this is a close approximation.
self.db.mem_used() + Self::mem_used_impl(&self.account_cache.lock())
self.db.mem_used()
+ Self::mem_used_impl(&self.account_cache.lock())
+ Self::mem_used_impl(&self.shard_cache.lock())
+ Self::mem_used_impl(&self.asset_scheme_cache.lock())
+ Self::mem_used_impl(&self.asset_cache.lock())
Expand Down
3 changes: 2 additions & 1 deletion keystore/src/accounts_dir/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ where
fn remove(&self, account: &SafeAccount) -> Result<(), Error> {
// enumerate all entries in keystore
// and find entry with given address
let to_remove = self.files_content()?
let to_remove = self
.files_content()?
.into_iter()
.find(|&(_, ref acc)| acc.id == account.id && acc.address == account.address);

Expand Down
9 changes: 6 additions & 3 deletions network/src/p2p/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ impl Manager {

let local_node_id =
self.routing_table.local_node_id(&remote_node_id).ok_or(Error::General("Not handshaked"))?;
let session = self.routing_table
let session = self
.routing_table
.unestablished_session(&socket_address)
.ok_or(Error::General("Session doesn't exist"))?;

Expand Down Expand Up @@ -210,7 +211,8 @@ impl Manager {
node_id,
..
}) => {
let remote_addr = self.connections
let remote_addr = self
.connections
.remote_addr_of_waiting_sync(stream)
.ok_or(Error::General("Cannot find remote address"))?;
let remote_node_id = convert_to_node_id(remote_addr.ip(), port);
Expand All @@ -223,7 +225,8 @@ impl Manager {
}

let remote_addr = SocketAddr::new(remote_addr.ip(), port);
let session = self.routing_table
let session = self
.routing_table
.unestablished_session(&remote_addr)
.ok_or(Error::General("Cannot find session"))?;
if !signed_message.is_valid(&session) {
Expand Down
6 changes: 4 additions & 2 deletions network/src/session_initiator/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ impl SessionInitiator {
let message = message::Message::nonce_request(seq as u64, encrypted_nonce);
self.server.enqueue(message, from.clone())?;
} else {
let requester_pub_key = self.routing_table
let requester_pub_key = self
.routing_table
.register_key_pair_for_secret(from)
.ok_or(Error::General("Cannot register key pair"))?;

Expand Down Expand Up @@ -303,7 +304,8 @@ impl SessionInitiator {
return Ok(())
}

let _secret = self.routing_table
let _secret = self
.routing_table
.share_secret(from, responder_pub_key)
.ok_or(Error::General("Cannot share secret"))?;
let encrypted_nonce =
Expand Down
3 changes: 2 additions & 1 deletion rpc/src/v1/impls/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ impl Account for AccountClient {
}

fn create_account(&self, passphrase: Option<String>) -> Result<Address> {
let (address, _) = self.account_provider
let (address, _) = self
.account_provider
.new_account_and_public(passphrase.unwrap_or_default().as_ref())
.map_err(account_provider)?;
Ok(address)
Expand Down
7 changes: 3 additions & 4 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
indent_style = "Block"
use_small_heuristics = false # true
use_small_heuristics = "Off" # "Default"
binop_separator = "Front"
# combine_control_expr = true
comment_width = 120 # 80
Expand All @@ -18,12 +18,14 @@ format_strings = false
hard_tabs = false
imports_indent = "Block" # "Visual"
imports_layout = "Mixed"
merge_imports = false
match_block_trailing_comma = false
max_width = 120 # 100
merge_derives = true
# force_multiline_blocks = false
newline_style = "Unix"
normalize_comments = false
remove_nested_parens = true
reorder_imports = true
reorder_modules = true
# reorder_impl_items = false
Expand All @@ -34,7 +36,6 @@ space_after_colon = true
space_before_colon = false
struct_field_align_threshold = 0
spaces_around_ranges = false
spaces_within_parens_and_brackets = false
## struct_lit_single_line = true
tab_spaces = 4
trailing_comma = "Vertical"
Expand All @@ -44,10 +45,8 @@ use_field_init_shorthand = true # false
use_try_shorthand = true # false
wrap_comments = false
match_arm_blocks = true
write_mode = "Overwrite"
blank_lines_upper_bound = 2 # 1
blank_lines_lower_bound = 0
remove_blank_lines_at_start_or_end_of_block = true
hide_parse_errors = false
color = "Always" # "Auto"
unstable_features = false
Expand Down
6 changes: 4 additions & 2 deletions types/src/transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ impl Encodable for Transaction {
},
registrar,
nonce,
} => s.begin_list(8)
} => s
.begin_list(8)
.append(&ASSET_MINT_ID)
.append(network_id)
.append(metadata)
Expand All @@ -192,7 +193,8 @@ impl Encodable for Transaction {
inputs,
outputs,
nonce,
} => s.begin_list(6)
} => s
.begin_list(6)
.append(&ASSET_TRANSFER_ID)
.append(network_id)
.append_list(burns)
Expand Down
3 changes: 2 additions & 1 deletion util/io/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ where
IoMessage::AddHandler {
handler,
} => {
let handler_id = self.handlers
let handler_id = self
.handlers
.write()
.insert(handler.clone())
.unwrap_or_else(|_| panic!("Too many handlers registered"));
Expand Down
Loading