Skip to content

Commit

Permalink
Upgrade to rust 1.39.0 (solana-labs#6939)
Browse files Browse the repository at this point in the history
* Upgrade to rust 1.39.0

* 1.39.0 clippy
  • Loading branch information
mvines authored Nov 14, 2019
1 parent f108f48 commit e7f63cd
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-rust-nightly/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM solanalabs/rust:1.38.0
FROM solanalabs/rust:1.39.0
ARG date

RUN set -x \
Expand Down
2 changes: 1 addition & 1 deletion ci/docker-rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions ci/rust-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion core/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl ClusterInfo {
fn gossip_request(&mut self, stakes: &HashMap<Pubkey, u64>) -> 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
Expand Down
1 change: 1 addition & 0 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn error::Error>> {
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();
Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/leader_schedule_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pubkey> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/storage_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn validator_accounts(bank: &Bank) -> HashMap<Pubkey, Account> {
.iter()
.filter_map(|account_id| {
bank.get_account(account_id)
.and_then(|account| Some((*account_id, account)))
.map(|account| (*account_id, account))
})
.collect()
}
Expand All @@ -73,7 +73,7 @@ pub fn archiver_accounts(bank: &Bank) -> HashMap<Pubkey, Account> {
.iter()
.filter_map(|account_id| {
bank.get_account(account_id)
.and_then(|account| Some((*account_id, account)))
.map(|account| (*account_id, account))
})
.collect()
}
Expand Down
21 changes: 21 additions & 0 deletions sdk-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl Transaction {
}
}

/// # Safety
pub unsafe fn into_native(self) -> TransactionNative {
TransactionNative {
signatures: CVec::into_native(self.signatures)
Expand All @@ -54,6 +55,7 @@ impl Transaction {
}
}

/// # Safety
#[allow(clippy::should_implement_trait)]
pub unsafe fn clone(&self) -> Self {
Self {
Expand Down Expand Up @@ -283,36 +285,43 @@ impl CVec<CompiledInstruction> {
}
}

/// # 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);
Expand All @@ -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(
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountInfo<'a>>, &'a [u8]) {
let mut offset: usize = 0;
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/instruction_processor_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn next_keyed_account<I: Iterator>(iter: &mut I) -> Result<I::Item, Instruct
iter.next().ok_or(InstructionError::NotEnoughAccountKeys)
}

pub fn limited_deserialize<T>(data: &[u8]) -> Result<(T), InstructionError>
pub fn limited_deserialize<T>(data: &[u8]) -> Result<T, InstructionError>
where
T: serde::de::DeserializeOwned,
{
Expand Down

0 comments on commit e7f63cd

Please sign in to comment.