diff --git a/README.md b/README.md index b04121adb98a64..1e866b44d034e9 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ $ source $HOME/.cargo/env $ rustup component add rustfmt ``` -If your rustc version is lower than 1.38.0, please update it: +If your rustc version is lower than 1.39.0, please update it: ```bash $ rustup update diff --git a/ci/docker-rust-nightly/Dockerfile b/ci/docker-rust-nightly/Dockerfile index 8972023e14e445..2ee345a555a740 100644 --- a/ci/docker-rust-nightly/Dockerfile +++ b/ci/docker-rust-nightly/Dockerfile @@ -1,4 +1,4 @@ -FROM solanalabs/rust:1.38.0 +FROM solanalabs/rust:1.39.0 ARG date RUN set -x \ diff --git a/ci/docker-rust/Dockerfile b/ci/docker-rust/Dockerfile index 6cf3f101b42eac..b9e5ea6c18489f 100644 --- a/ci/docker-rust/Dockerfile +++ b/ci/docker-rust/Dockerfile @@ -1,6 +1,6 @@ # Note: when the rust version is changed also modify # ci/rust-version.sh to pick up the new image tag -FROM rust:1.38.0 +FROM rust:1.39.0 # Add Google Protocol Buffers for Libra's metrics library. ENV PROTOC_VERSION 3.8.0 diff --git a/ci/rust-version.sh b/ci/rust-version.sh index 07ca557d7e6164..8aedcc1139f845 100644 --- a/ci/rust-version.sh +++ b/ci/rust-version.sh @@ -13,8 +13,8 @@ # $ source ci/rust-version.sh # -stable_version=1.38.0 -nightly_version=2019-10-03 +stable_version=1.39.0 +nightly_version=2019-11-13 export rust_stable="$stable_version" export rust_stable_docker_image=solanalabs/rust:"$stable_version" diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 6536d5fd702c55..14afa66d43a517 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -990,7 +990,7 @@ impl ClusterInfo { fn gossip_request(&mut self, stakes: &HashMap) -> Vec<(SocketAddr, Protocol)> { let pulls: Vec<_> = self.new_pull_requests(stakes); let pushes: Vec<_> = self.new_push_requests(); - vec![pulls, pushes].into_iter().flat_map(|x| x).collect() + vec![pulls, pushes].into_iter().flatten().collect() } /// At random pick a node and try to get updated changes from them diff --git a/genesis/src/main.rs b/genesis/src/main.rs index e51aca79d44cb7..ece329fc6a9063 100644 --- a/genesis/src/main.rs +++ b/genesis/src/main.rs @@ -83,6 +83,7 @@ pub fn add_genesis_accounts(file: &str, genesis_config: &mut GenesisConfig) -> i Ok(()) } +#[allow(clippy::cognitive_complexity)] fn main() -> Result<(), Box> { let default_bootstrap_leader_lamports = &sol_to_lamports(500.0).to_string(); let default_bootstrap_leader_stake_lamports = &sol_to_lamports(0.5).to_string(); diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 1346415c597abc..780eb5dd98016d 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -388,6 +388,7 @@ fn graph_forks( dot.join("\n") } +#[allow(clippy::cognitive_complexity)] fn main() { const DEFAULT_ROOT_COUNT: &str = "1"; solana_logger::setup_with_filter("solana=info"); diff --git a/ledger/src/leader_schedule_cache.rs b/ledger/src/leader_schedule_cache.rs index 56e03a4122022e..178bbb2f1688c8 100644 --- a/ledger/src/leader_schedule_cache.rs +++ b/ledger/src/leader_schedule_cache.rs @@ -150,7 +150,7 @@ impl LeaderScheduleCache { } start_index = 0; } - first_slot.and_then(|slot| Some((slot, last_slot))) + first_slot.map(|slot| (slot, last_slot)) } fn slot_leader_at_no_compute(&self, slot: Slot) -> Option { diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index 205434e7de40b2..cc558a9c85d7d0 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -300,7 +300,7 @@ impl Accounts { }, ); - let mut versions: Vec<(Pubkey, u64, B)> = accumulator.into_iter().flat_map(|x| x).collect(); + let mut versions: Vec<(Pubkey, u64, B)> = accumulator.into_iter().flatten().collect(); self.accounts_db.thread_pool.install(|| { versions.par_sort_by_key(|s| (s.0, s.1)); }); diff --git a/runtime/src/storage_utils.rs b/runtime/src/storage_utils.rs index 97524afb04f3dc..6e006680699bd5 100644 --- a/runtime/src/storage_utils.rs +++ b/runtime/src/storage_utils.rs @@ -62,7 +62,7 @@ pub fn validator_accounts(bank: &Bank) -> HashMap { .iter() .filter_map(|account_id| { bank.get_account(account_id) - .and_then(|account| Some((*account_id, account))) + .map(|account| (*account_id, account)) }) .collect() } @@ -73,7 +73,7 @@ pub fn archiver_accounts(bank: &Bank) -> HashMap { .iter() .filter_map(|account_id| { bank.get_account(account_id) - .and_then(|account| Some((*account_id, account))) + .map(|account| (*account_id, account)) }) .collect() } diff --git a/sdk-c/src/lib.rs b/sdk-c/src/lib.rs index d74a6214cbc4ad..e96c9749d7d4a9 100644 --- a/sdk-c/src/lib.rs +++ b/sdk-c/src/lib.rs @@ -44,6 +44,7 @@ impl Transaction { } } + /// # Safety pub unsafe fn into_native(self) -> TransactionNative { TransactionNative { signatures: CVec::into_native(self.signatures) @@ -54,6 +55,7 @@ impl Transaction { } } + /// # Safety #[allow(clippy::should_implement_trait)] pub unsafe fn clone(&self) -> Self { Self { @@ -283,36 +285,43 @@ impl CVec { } } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_transaction(tx: *mut Transaction) { Box::from_raw(tx); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_message(m: *mut Message) { Box::from_raw(m); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_message_header(mh: *mut MessageHeader) { Box::from_raw(mh); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_signature(s: *mut Signature) { Box::from_raw(s); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_compiled_instruction(i: *mut CompiledInstruction) { Box::from_raw(i); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn free_c_string(s: *mut c_char) { CString::from_raw(s); } +/// # Safety #[no_mangle] pub unsafe extern "C" fn new_unsigned_transaction(message: *mut Message) -> *mut Transaction { let message = Box::from_raw(message); @@ -327,6 +336,8 @@ pub unsafe extern "C" fn new_unsigned_transaction(message: *mut Message) -> *mut /// # Undefined Behavior /// /// Causes UB if `seed` is not a pointer to an array of length 32 or if `seed` is `NULL` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn generate_keypair(seed: *const u8) -> *mut Keypair { let seed = <&[u8] as TryInto<&[u8; PUBLIC_KEY_LENGTH]>>::try_into(slice::from_raw_parts( @@ -345,6 +356,8 @@ pub unsafe extern "C" fn generate_keypair(seed: *const u8) -> *mut Keypair { /// # Undefined Behavior /// /// Causes UB if `keypair` is `NULL` or if `keypair` in not a pointer to a valid `Keypair` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn get_keypair_pubkey(keypair: *const Keypair) -> *mut Pubkey { let keypair = if let Ok(k) = (*keypair).new_native() { @@ -362,6 +375,8 @@ pub unsafe extern "C" fn get_keypair_pubkey(keypair: *const Keypair) -> *mut Pub /// # Undefined Behavior /// /// Causes UB if any of the input pointers is `NULL`, or if `tx` is not a valid `Transaction` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn serialize_transaction( tx: *mut Transaction, @@ -387,6 +402,8 @@ pub unsafe extern "C" fn serialize_transaction( /// # Undefined Behavior /// /// Causes UB if `bytes` is `NULL`, or if `bytes` does not point to a valid array of length `len` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn deserialize_transaction( bytes: *const u8, @@ -410,6 +427,8 @@ pub unsafe extern "C" fn deserialize_transaction( /// /// Causes UB if any of the pointers is `NULL`, or if `keypairs` does not point to a valid array of /// `Keypairs` of length `num_keypairs` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn transaction_partial_sign( tx: *mut Transaction, @@ -459,6 +478,8 @@ pub unsafe extern "C" fn transaction_partial_sign( /// /// Causes UB if `pubkey` is `NULL`, or if the returned c-string is freed by any method other than /// calling `free_c_string()` +/// +/// # Safety #[no_mangle] pub unsafe extern "C" fn get_pubkey_string(pubkey: *const Pubkey) -> *mut c_char { if let Ok(s) = CString::new(format!("{}", *pubkey)) { diff --git a/sdk/src/entrypoint.rs b/sdk/src/entrypoint.rs index e12da85e3face8..2a5705114286aa 100644 --- a/sdk/src/entrypoint.rs +++ b/sdk/src/entrypoint.rs @@ -38,6 +38,8 @@ macro_rules! entrypoint { } /// Deserialize the input parameters +/// +/// # Safety #[allow(clippy::type_complexity)] pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec>, &'a [u8]) { let mut offset: usize = 0; diff --git a/sdk/src/instruction_processor_utils.rs b/sdk/src/instruction_processor_utils.rs index 338234fd254588..6cd7ef70f77680 100644 --- a/sdk/src/instruction_processor_utils.rs +++ b/sdk/src/instruction_processor_utils.rs @@ -41,7 +41,7 @@ pub fn next_keyed_account(iter: &mut I) -> Result(data: &[u8]) -> Result<(T), InstructionError> +pub fn limited_deserialize(data: &[u8]) -> Result where T: serde::de::DeserializeOwned, {