Skip to content

Commit

Permalink
Fix some nightly warnings (solana-labs#5093)
Browse files Browse the repository at this point in the history
ONCE_INIT => Once::new
Box<Error> => Box<dyn Error>
  • Loading branch information
sakridge authored Jul 14, 2019
1 parent 440d006 commit 9b54528
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//! `setup()` may be called multiple times.
use env_logger;
use std::sync::{Once, ONCE_INIT};
use std::sync::Once;

static INIT: Once = ONCE_INIT;
static INIT: Once = Once::new();

/// Setup function that is only run once, even if called multiple times.
pub fn setup() {
Expand Down
6 changes: 3 additions & 3 deletions metrics/src/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ macro_rules! inc_new_counter {
if log_enabled!($level) {
static mut INC_NEW_COUNTER: $crate::counter::Counter =
create_counter!($name, $lograte, $metricsrate);
static INIT_HOOK: std::sync::Once = std::sync::ONCE_INIT;
static INIT_HOOK: std::sync::Once = std::sync::Once::new();
unsafe {
INIT_HOOK.call_once(|| {
INC_NEW_COUNTER.init();
Expand Down Expand Up @@ -197,11 +197,11 @@ mod tests {
use serial_test_derive::serial;
use std::env;
use std::sync::atomic::Ordering;
use std::sync::{Once, RwLock, ONCE_INIT};
use std::sync::{Once, RwLock};

fn get_env_lock() -> &'static RwLock<()> {
static mut ENV_LOCK: Option<RwLock<()>> = None;
static INIT_HOOK: Once = ONCE_INIT;
static INIT_HOOK: Once = Once::new();

unsafe {
INIT_HOOK.call_once(|| {
Expand Down
6 changes: 3 additions & 3 deletions metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use solana_sdk::hash::hash;
use solana_sdk::timing;
use std::collections::HashMap;
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
use std::sync::{Arc, Barrier, Mutex, Once, ONCE_INIT};
use std::sync::{Arc, Barrier, Mutex, Once};
use std::thread;
use std::time::{Duration, Instant};
use std::{cmp, env};
Expand Down Expand Up @@ -379,7 +379,7 @@ impl Drop for MetricsAgent {
}

fn get_singleton_agent() -> Arc<Mutex<MetricsAgent>> {
static INIT: Once = ONCE_INIT;
static INIT: Once = Once::new();
static mut AGENT: Option<Arc<Mutex<MetricsAgent>>> = None;
unsafe {
INIT.call_once(|| AGENT = Some(Arc::new(Mutex::new(MetricsAgent::default()))));
Expand Down Expand Up @@ -430,7 +430,7 @@ pub fn flush() {
/// Hook the panic handler to generate a data point on each panic
pub fn set_panic_hook(program: &'static str) {
use std::panic;
static SET_HOOK: Once = ONCE_INIT;
static SET_HOOK: Once = Once::new();
SET_HOOK.call_once(|| {
let default_hook = panic::take_hook();
panic::set_hook(Box::new(move |ono| {
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/pubkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl fmt::Display for Pubkey {
}
}

pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box<error::Error>> {
pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box<dyn error::Error>> {
let printable = format!("{}", pubkey);
let serialized = serde_json::to_string(&printable)?;

Expand All @@ -82,7 +82,7 @@ pub fn write_pubkey(outfile: &str, pubkey: Pubkey) -> Result<(), Box<error::Erro
Ok(())
}

pub fn read_pubkey(infile: &str) -> Result<Pubkey, Box<error::Error>> {
pub fn read_pubkey(infile: &str) -> Result<Pubkey, Box<dyn error::Error>> {
let f = File::open(infile.to_string())?;
let printable: String = serde_json::from_reader(f)?;
Ok(Pubkey::from_str(&printable)?)
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
}

#[test]
fn test_read_write_pubkey() -> Result<(), Box<error::Error>> {
fn test_read_write_pubkey() -> Result<(), Box<dyn error::Error>> {
let filename = "test_pubkey.json";
let pubkey = Pubkey::new_rand();
write_pubkey(filename, pubkey)?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ impl KeypairUtil for Keypair {
}
}

pub fn read_keypair(path: &str) -> Result<Keypair, Box<error::Error>> {
pub fn read_keypair(path: &str) -> Result<Keypair, Box<dyn error::Error>> {
let file = File::open(path.to_string())?;
let bytes: Vec<u8> = serde_json::from_reader(file)?;
let keypair = Keypair::from_bytes(&bytes)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
Ok(keypair)
}

pub fn gen_keypair_file(outfile: &str) -> Result<String, Box<error::Error>> {
pub fn gen_keypair_file(outfile: &str) -> Result<String, Box<dyn error::Error>> {
let keypair_bytes = Keypair::new().to_bytes();
let serialized = serde_json::to_string(&keypair_bytes.to_vec())?;

Expand Down

0 comments on commit 9b54528

Please sign in to comment.