Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Jun 6, 2019
1 parent 30ce1ff commit 5cd746c
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/db/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn no_args() -> impl Iterator<Item = &'static str> {

enum MigrationKind {
SQL(&'static str),
Code(Box<Fn(&Transaction) -> ::rusqlite::Result<()>>),
Code(Box<dyn Fn(&Transaction) -> ::rusqlite::Result<()>>),
}

fn migrations() -> Vec<(&'static str, MigrationKind)> {
Expand Down
13 changes: 8 additions & 5 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ struct ConnectionCustomizer;

impl CustomizeConnection<Connection, ::rusqlite::Error> for ConnectionCustomizer {
fn on_acquire(&self, conn: &mut Connection) -> Result<(), ::rusqlite::Error> {
conn.execute("PRAGMA foreign_keys = ON;", ::std::iter::empty::<&ToSql>())?;
conn.execute(
"PRAGMA foreign_keys = ON;",
::std::iter::empty::<&dyn ToSql>(),
)?;
Ok(())
}
}
Expand Down Expand Up @@ -118,7 +121,7 @@ impl<'a> TransactionHandle<'a> {
pub trait QueryUtils {
fn with_conn<T, F: FnOnce(&Connection) -> Fallible<T>>(&self, f: F) -> Fallible<T>;

fn exists(&self, sql: &str, params: &[&ToSql]) -> Fallible<bool> {
fn exists(&self, sql: &str, params: &[&dyn ToSql]) -> Fallible<bool> {
self.with_conn(|conn| {
self.trace(sql, || {
let mut prepared = conn.prepare(sql)?;
Expand All @@ -127,7 +130,7 @@ pub trait QueryUtils {
})
}

fn execute(&self, sql: &str, params: &[&ToSql]) -> Fallible<usize> {
fn execute(&self, sql: &str, params: &[&dyn ToSql]) -> Fallible<usize> {
self.with_conn(|conn| {
self.trace(sql, || {
let mut prepared = conn.prepare(sql)?;
Expand All @@ -140,7 +143,7 @@ pub trait QueryUtils {
fn get_row<T, F: FnMut(&Row) -> T>(
&self,
sql: &str,
params: &[&ToSql],
params: &[&dyn ToSql],
func: F,
) -> Fallible<Option<T>> {
self.with_conn(|conn| {
Expand All @@ -160,7 +163,7 @@ pub trait QueryUtils {
fn query<T, F: FnMut(&Row) -> T>(
&self,
sql: &str,
params: &[&ToSql],
params: &[&dyn ToSql],
func: F,
) -> Fallible<Vec<T>> {
self.with_conn(|conn| {
Expand Down
13 changes: 8 additions & 5 deletions src/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,23 @@ pub use self::storage::LogStorage;
static INIT_LOGS: Once = Once::new();

thread_local! {
static SCOPED: RefCell<Vec<Box<Log>>> = RefCell::new(Vec::new());
static SCOPED: RefCell<Vec<Box<dyn Log>>> = RefCell::new(Vec::new());
}

struct MultiLogger {
global: Vec<Box<Log>>,
scoped: &'static LocalKey<RefCell<Vec<Box<Log>>>>,
global: Vec<Box<dyn Log>>,
scoped: &'static LocalKey<RefCell<Vec<Box<dyn Log>>>>,
}

impl MultiLogger {
fn new(global: Vec<Box<Log>>, scoped: &'static LocalKey<RefCell<Vec<Box<Log>>>>) -> Self {
fn new(
global: Vec<Box<dyn Log>>,
scoped: &'static LocalKey<RefCell<Vec<Box<dyn Log>>>>,
) -> Self {
MultiLogger { global, scoped }
}

fn each<F: FnMut(&Log)>(&self, mut f: F) {
fn each<F: FnMut(&dyn Log)>(&self, mut f: F) {
for logger in &self.global {
f(logger.as_ref());
}
Expand Down
6 changes: 3 additions & 3 deletions src/report/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl FromStr for S3Prefix {

pub struct S3Writer {
prefix: S3Prefix,
client: Box<S3>,
client: Box<dyn S3>,
}

pub fn get_client_for_bucket(bucket: &str) -> Fallible<Box<S3>> {
pub fn get_client_for_bucket(bucket: &str) -> Fallible<Box<dyn S3>> {
let make_client = |region| -> Fallible<S3Client> {
let credentials = DefaultCredentialsProvider::new().unwrap();
Ok(S3Client::new_with(HttpClient::new()?, credentials, region))
Expand All @@ -87,7 +87,7 @@ pub fn get_client_for_bucket(bucket: &str) -> Fallible<Box<S3>> {
const S3RETRIES: u64 = 4;

impl S3Writer {
pub fn create(client: Box<S3>, prefix: S3Prefix) -> Fallible<S3Writer> {
pub fn create(client: Box<dyn S3>, prefix: S3Prefix) -> Fallible<S3Writer> {
Ok(S3Writer { prefix, client })
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Agents {
fn synchronize(&self, tokens: &Tokens) -> Fallible<()> {
self.db.transaction(|trans| {
let mut real = tokens.agents.values().collect::<HashSet<&String>>();
for agent in self.all()? {
for agent in &self.all()? {
if !real.remove(&agent.name) {
trans.execute("DELETE FROM agents WHERE name = ?1;", &[&agent.name])?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/routes/ui/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn endpoint_queue(data: Arc<Data>) -> Fallible<Response<Body>> {
let mut generating_report = Vec::new();
let mut report_failed = Vec::new();

for experiment in Experiment::unfinished(&data.db)? {
for experiment in &Experiment::unfinished(&data.db)? {
// Don't include completed experiments in the queue
if experiment.status == Status::Completed {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub(crate) static RUSTUP_TOOLCHAIN_INSTALL_MASTER: BinaryCrate = BinaryCrate {
cargo_subcommand: None,
};

static INSTALLABLE_TOOLS: &[&InstallableTool] = &[
static INSTALLABLE_TOOLS: &[&dyn InstallableTool] = &[
&RUSTUP,
&CARGO_INSTALL_UPDATE,
&RUSTUP_TOOLCHAIN_INSTALL_MASTER,
Expand Down
6 changes: 3 additions & 3 deletions src/utils/hex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub(crate) fn from_hex(input: &str) -> Result<Vec<u8>, HexError> {
pending += 1;

current = match byte {
b'0'...b'9' => byte - b'0',
b'a'...b'f' => byte - b'a' + 10,
b'A'...b'F' => byte - b'A' + 10,
b'0'..=b'9' => byte - b'0',
b'a'..=b'f' => byte - b'a' + 10,
b'A'..=b'F' => byte - b'A' + 10,
_ => {
return Err(HexError::InvalidChar(input[i..].chars().next().unwrap()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
f()
}

pub fn report_panic(e: &Any) {
pub fn report_panic(e: &dyn Any) {
if let Some(e) = e.downcast_ref::<String>() {
error!("panicked: {}", e)
} else if let Some(e) = e.downcast_ref::<&'static str>() {
Expand Down

0 comments on commit 5cd746c

Please sign in to comment.