Skip to content

Commit

Permalink
change the rust version from 1.64.0 to 1.66.0 (#3874)
Browse files Browse the repository at this point in the history
* change the rust version from 1.64.0 to 1.65.0

* fix the warning caused by clippy for updating the rust from 1.64.0 to 1.65.0(#3873)

* fix fmt check

* use the rustc of version 1.66.0 to satify the requirement of nextest-runner v0.37.0

* fix the warnings from the rust clippy

* remove the unnessesary mut
  • Loading branch information
jackzhhuang authored Mar 22, 2023
1 parent bc5f9e3 commit 4856e37
Show file tree
Hide file tree
Showing 42 changed files with 94 additions and 89 deletions.
2 changes: 1 addition & 1 deletion abi/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ impl<'d> serde::de::DeserializeSeed<'d> for &TypeInstantiation {
T::Vector(layout) => Ok(match layout.as_ref() {
T::U8 => {
let bytes = <Vec<u8>>::deserialize(deserializer)?;
V::String(format!("0x{}", hex::encode(&bytes)))
V::String(format!("0x{}", hex::encode(bytes)))
}
_ => V::Array(deserializer.deserialize_seq(VectorElementVisitor(layout.as_ref()))?),
}),
Expand Down
10 changes: 6 additions & 4 deletions account/api/src/rich_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,25 @@ pub struct Setting {
}

impl Setting {
pub fn default() -> Self {
pub fn readonly() -> Self {
Setting {
default_expiration_timeout: 3600,
default_gas_price: 1,
default_gas_token: G_STC_TOKEN_CODE.clone(),
is_default: false,
is_readonly: false,
is_readonly: true,
}
}
}

pub fn readonly() -> Self {
impl std::default::Default for Setting {
fn default() -> Self {
Setting {
default_expiration_timeout: 3600,
default_gas_price: 1,
default_gas_token: G_STC_TOKEN_CODE.clone(),
is_default: false,
is_readonly: true,
is_readonly: false,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion account/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Account {
None
} else {
let decrypted_key = storage
.decrypt_private_key(addr, password.unwrap_or_else(|| "".to_string()))
.decrypt_private_key(addr, password.unwrap_or_default())
.map_err(|e| {
warn!(
"Try to unlock {} with a invalid password, err: {:?}",
Expand Down
4 changes: 2 additions & 2 deletions chain/tests/block_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ prop_compose! {
storage in Just(storage),
) -> Block {
//transfer transactions
let mut account = AccountInfoUniverse::default().unwrap();
let mut account = AccountInfoUniverse::default();
let mut txns = txn_transfer(&mut account, gens);
let user_txns = {
let mut t= vec![];
Expand Down Expand Up @@ -274,7 +274,7 @@ proptest! {
1..2
), ) {
let chain_state = ChainStateDB::new(Arc::new(storage), None);
let mut account = AccountInfoUniverse::default().unwrap();
let mut account = AccountInfoUniverse::default();
let txns = txn_transfer(&mut account, gens);
let result = block_execute(&chain_state, txns, 0, None);
info!("execute result: {:?}", result);
Expand Down
3 changes: 3 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ cognitive-complexity-threshold = 100
type-complexity-threshold = 10000
# manipulating complex states machines in consensus
too-many-arguments-threshold = 13
# a Result is at least as large as the Err-variant.
# the default value 128 is too small
large-error-threshold = 256
2 changes: 1 addition & 1 deletion cmd/generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn init_or_load_data_dir(
let account = match manager.default_account_info()? {
Some(account) => account,
None => manager
.create_account(&password.unwrap_or_else(|| "".to_string()))?
.create_account(&password.unwrap_or_default())?
.info(),
};
Ok((config, storage, chain_info, account))
Expand Down
2 changes: 1 addition & 1 deletion cmd/miner_client/src/stratum_client_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl ServiceFactory<StratumClientService> for StratumClientServiceServiceFactory
fn create(ctx: &mut ServiceContext<StratumClientService>) -> Result<StratumClientService> {
let cfg = ctx.get_shared::<MinerClientConfig>()?;
let addr = cfg.server.unwrap_or_else(|| "127.0.0.1:9880".into());
let tcp_stream = Some(std::net::TcpStream::connect(&addr)?);
let tcp_stream = Some(std::net::TcpStream::connect(addr)?);
Ok(StratumClientService {
sender: None,
tcp_stream,
Expand Down
4 changes: 1 addition & 3 deletions cmd/starcoin/src/account/import_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ impl CommandAction for ImportCommand {
let private_key = match (opt.from_input.as_ref(), opt.from_file.as_ref()) {
(Some(p), _) => AccountPrivateKey::from_encoded_string(p)?,
(None, Some(p)) => {
let data = std::fs::read_to_string(p)?
.replace('\n', "")
.replace('\r', "");
let data = std::fs::read_to_string(p)?.replace(['\n', '\r'], "");
AccountPrivateKey::from_encoded_string(data.as_str())?
}
(None, None) => {
Expand Down
2 changes: 1 addition & 1 deletion commons/accumulator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Accumulator for MerkleAccumulator {

fn get_proof(&self, leaf_index: u64) -> Result<Option<AccumulatorProof>> {
let mut tree_guard = self.tree.lock();
if leaf_index > tree_guard.num_leaves as u64 {
if leaf_index > tree_guard.num_leaves {
return Ok(None);
}

Expand Down
6 changes: 3 additions & 3 deletions commons/accumulator/src/node_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ impl NodeIndex {

pub fn root_from_leaf_count(leaf_count: LeafCount) -> Self {
assert!(leaf_count > 0);
Self::root_from_leaf_index((leaf_count - 1) as u64)
Self::root_from_leaf_index(leaf_count - 1)
}

pub fn root_level_from_leaf_count(leaf_count: LeafCount) -> u32 {
assert!(leaf_count > 0);
let index = (leaf_count - 1) as u64;
let index = leaf_count - 1;
MAX_ACCUMULATOR_PROOF_DEPTH as u32 + 1 - index.leading_zeros()
}

Expand Down Expand Up @@ -350,7 +350,7 @@ impl Iterator for FrozenSubtreeSiblingIterator {
self.remaining_new_leaves -= next_subtree_leaves;

Some(NodeIndex::from_inorder_index(
(first_leaf_index + last_leaf_index) as u64,
first_leaf_index + last_leaf_index,
))
}
}
Expand Down
4 changes: 2 additions & 2 deletions commons/accumulator/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl AccumulatorTree {
// placeholder hash nodes as needed on the right, and left siblings that have either
// been newly created or read from storage.
let (mut pos, mut hash) = left_siblings.pop().expect("Must have at least one node");
for _ in pos.level()..root_level as u32 {
for _ in pos.level()..root_level {
hash = if pos.is_left_child() {
let not_frozen = AccumulatorNode::new_internal(
pos.parent(),
Expand Down Expand Up @@ -378,7 +378,7 @@ impl AccumulatorTree {
if self.num_leaves == 0 {
0_u64
} else {
(self.num_leaves - 1) as u64
self.num_leaves - 1
}
}

Expand Down
2 changes: 1 addition & 1 deletion commons/forkable-jellyfish-merkle/src/node_type/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl InternalNode {

/// Get all child hash
pub fn all_child(&self) -> Vec<HashValue> {
self.children.iter().map(|(_, c)| c.hash).collect()
self.children.values().map(|c| c.hash).collect()
}
}

Expand Down
2 changes: 1 addition & 1 deletion commons/logger/src/structured_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ pub fn with_logger<F, R>(f: F) -> R
where
F: FnOnce(&Logger) -> R,
{
f(&(*G_GLOBAL_SLOG_LOGGER.load()))
f(&G_GLOBAL_SLOG_LOGGER.load())
}
4 changes: 2 additions & 2 deletions commons/scmd/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ where

/// Execute command by parse std::env::args_os() and print result.
pub fn exec(self) -> Result<()> {
let (output_format, result) = self.exec_inner(&mut std::env::args_os())?;
let (output_format, result) = self.exec_inner(std::env::args_os())?;
print_action_result(output_format, &result_to_json(&result))
}

Expand Down Expand Up @@ -268,7 +268,7 @@ where
.arg(
Arg::new("format")
.takes_value(true)
.possible_values(&["json", "table"])
.possible_values(["json", "table"])
.ignore_case(true)
.default_value("json")
.help("Output format should be json or table."),
Expand Down
2 changes: 1 addition & 1 deletion commons/time-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl TimeService for RealTimeService {
}

fn now_secs(&self) -> u64 {
duration_since_epoch().as_secs() as u64
duration_since_epoch().as_secs()
}

fn now_millis(&self) -> u64 {
Expand Down
4 changes: 2 additions & 2 deletions dataformat-generator/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn generate() -> Result<(), Error> {
tracer.trace_type::<SignedMessage>(&samples)?;
let registry = tracer.registry()?;
let data = serde_yaml::to_string(&registry).unwrap();
std::fs::write("../etc/starcoin_types.yml", &data).unwrap();
std::fs::write("../etc/starcoin_types.yml", data).unwrap();

{
let mut tracer = Tracer::new(TracerConfig::default());
Expand All @@ -116,7 +116,7 @@ fn generate() -> Result<(), Error> {
tracer.trace_type::<NewBlockEvent>(&samples)?;
let registry = tracer.registry()?;
let data = serde_yaml::to_string(&registry).unwrap();
std::fs::write("../etc/onchain_events.yml", &data).unwrap();
std::fs::write("../etc/onchain_events.yml", data).unwrap();
}
// println!("{}", data);
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn main() {
.unwrap()
.join("../../genesis");

std::env::set_current_dir(&base_path).expect("failed to change directory");
std::env::set_current_dir(base_path).expect("failed to change directory");

let path = Path::new(G_GENESIS_GENERATED_DIR).join(net.to_string());
new_genesis.save(path.as_path()).expect("save genesis fail");
Expand Down
2 changes: 1 addition & 1 deletion network-p2p/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl NodeKeyConfig {

Ed25519(Secret::File(f)) => get_secret(
f,
|mut b| ed25519::SecretKey::from_bytes(&mut b),
|b| ed25519::SecretKey::from_bytes(b),
ed25519::SecretKey::generate,
|b| b.as_ref().to_vec(),
)
Expand Down
2 changes: 1 addition & 1 deletion network-rpc/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct GetBlockIds {

impl RpcRequest for GetBlockIds {
fn verify(&self) -> Result<()> {
if self.max_size as u64 > MAX_BLOCK_IDS_REQUEST_SIZE {
if self.max_size > MAX_BLOCK_IDS_REQUEST_SIZE {
return Err(NetRpcError::new(
RpcErrorCode::BadRequest,
format!("max_size is too big > {}", MAX_BLOCK_IDS_REQUEST_SIZE),
Expand Down
2 changes: 1 addition & 1 deletion network-rpc/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl RawRpcClient for InmemoryRpcClient {
Box::pin(
self.server
.handle_raw_request(self.self_peer_id.clone(), rpc_path, message)
.then(|result| async move { anyhow::Result::Ok(bcs_ext::to_bytes(&result)?) }),
.then(|result| async move { bcs_ext::to_bytes(&result) }),
)
}
}
6 changes: 3 additions & 3 deletions network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ impl ServiceHandler<Self, GetPeerSet> for NetworkActorService {
) -> <GetPeerSet as ServiceRequest>::Response {
self.inner
.peers
.iter()
.map(|(_, peer)| peer.get_peer_info().clone())
.values()
.map(|peer| peer.get_peer_info().clone())
.collect::<Vec<_>>()
}
}
Expand Down Expand Up @@ -853,7 +853,7 @@ where
let peers_len = peers.len();
// take sqrt(x) peers
let mut count = (peers_len as f64).powf(0.5).round() as u32;
count = count.min(max_peers).max(min_peers);
count = count.clamp(min_peers, max_peers);

let mut random = rand::thread_rng();
let mut peer_ids: Vec<_> = peers.cloned().collect();
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy.
# https://rust-lang.github.io/rustup/concepts/profiles.html
profile = "default"
channel = "1.64.0"
channel = "1.66.0"
4 changes: 2 additions & 2 deletions state/statedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl ChainStateDB {
.get_account_state_object(&table_handle_address(), true)
.expect("get account state success");
let state_root = account_state_object
.get(&*TABLE_PATH)
.get(&TABLE_PATH)
.expect("get state_root success");
if let Some(state_root) = state_root {
let hash = HashValue::from_slice(state_root.as_slice()).expect("hash value success");
Expand Down Expand Up @@ -362,7 +362,7 @@ impl ChainStateDB {
.get_account_state_object(&table_handle_address(), true)
.expect("get account state success");
let state_root = account_state_object
.get(&*TABLE_PATH)
.get(&TABLE_PATH)
.expect("get state_root success");
HashValue::from_slice(state_root.unwrap()).unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion storage/src/db_storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl DBStorage {
let inner = rocksdb::DB::open_cf_for_read_only(
db_opts,
path,
&column_families,
column_families,
error_if_log_file_exists,
)?;
Ok(inner)
Expand Down
2 changes: 1 addition & 1 deletion stratum/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl StratumJobResponse {
pub fn from(e: &MintBlockEvent, login: Option<LoginRequest>, worker_id: [u8; 4]) -> Self {
let mut minting_blob = e.minting_blob.clone();
let _ = minting_blob[35..39].borrow_mut().write_all(&worker_id);
let worker_id_hex = hex::encode(&worker_id);
let worker_id_hex = hex::encode(worker_id);
let job_id = hex::encode(&e.minting_blob[0..8]);
Self {
login,
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tasks/accumulator_sync_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl TaskState for BlockAccumulatorSyncTask {
}

fn next(&self) -> Option<Self> {
let next_start_number = self.start_number.saturating_add(self.batch_size as u64);
let next_start_number = self.start_number.saturating_add(self.batch_size);
if next_start_number >= self.target.num_leaves {
None
} else {
Expand Down
2 changes: 1 addition & 1 deletion sync/src/tasks/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ async fn test_block_sync_with_local() -> Result<()> {
current
});

assert_eq!(last_block_number as u64, total_blocks - 1);
assert_eq!(last_block_number, total_blocks - 1);

let report = event_handle.get_reports().pop().unwrap();
debug!("report: {}", report);
Expand Down
10 changes: 5 additions & 5 deletions vm/move-coverage/src/bin/coverage-summaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ fn main() {
let mut summary_writer: Box<dyn Write> = match &args.summary_path {
Some(x) => {
let path = Path::new(x);
Box::new(File::create(&path).unwrap())
Box::new(File::create(path).unwrap())
}
None => Box::new(io::stdout()),
};

let modules = get_modules(&args);
if args.derive_path_coverage {
let trace_map = if args.is_raw_trace_file {
TraceMap::from_trace_file(&input_trace_path)
TraceMap::from_trace_file(input_trace_path)
} else {
TraceMap::from_binary_file(&input_trace_path)
TraceMap::from_binary_file(input_trace_path)
};
if !args.csv_output {
format_human_summary(
Expand All @@ -108,9 +108,9 @@ fn main() {
}
} else {
let coverage_map = if args.is_raw_trace_file {
CoverageMap::from_trace_file(&input_trace_path)
CoverageMap::from_trace_file(input_trace_path)
} else {
CoverageMap::from_binary_file(&input_trace_path).unwrap()
CoverageMap::from_binary_file(input_trace_path).unwrap()
};
let unified_exec_map = coverage_map.to_unified_exec_map();
if !args.csv_output {
Expand Down
16 changes: 8 additions & 8 deletions vm/move-coverage/src/bin/move-trace-conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ fn main() {
if !args.use_trace_map {
let coverage_map = if let Some(old_coverage_path) = &args.update {
let path = Path::new(&old_coverage_path);
let old_coverage_map = CoverageMap::from_binary_file(&path).unwrap();
old_coverage_map.update_coverage_from_trace_file(&input_path)
let old_coverage_map = CoverageMap::from_binary_file(path).unwrap();
old_coverage_map.update_coverage_from_trace_file(input_path)
} else {
CoverageMap::from_trace_file(&input_path)
CoverageMap::from_trace_file(input_path)
};

output_map_to_file(&output_path, &coverage_map)
output_map_to_file(output_path, &coverage_map)
.expect("Unable to serialize coverage map to output file")
} else {
let trace_map = if let Some(old_trace_path) = &args.update {
let path = Path::new(&old_trace_path);
let old_trace_map = TraceMap::from_binary_file(&path);
old_trace_map.update_from_trace_file(&input_path)
let old_trace_map = TraceMap::from_binary_file(path);
old_trace_map.update_from_trace_file(input_path)
} else {
TraceMap::from_trace_file(&input_path)
TraceMap::from_trace_file(input_path)
};

output_map_to_file(&output_path, &trace_map)
output_map_to_file(output_path, &trace_map)
.expect("Unable to serialize trace map to output file")
}
}
Loading

0 comments on commit 4856e37

Please sign in to comment.