Skip to content

Commit

Permalink
clippy lints for rust 1.80.0 (#1436)
Browse files Browse the repository at this point in the history
Fixes to clippy lints for toolchain 1.80.0
  • Loading branch information
leftwo authored Aug 29, 2024
1 parent ea2282e commit 34cb612
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion agent/src/datafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl DataFile {
/*
* Look for an existing running snapshot.
*/
if inner.running_snapshots.get(&request.id).is_none() {
if !inner.running_snapshots.contains_key(&request.id) {
bail!("no running snapshots for region {}", request.id.0);
}

Expand Down
10 changes: 7 additions & 3 deletions agent/src/smf_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub trait SmfInstance {
>;
fn disable(&self, temporary: bool) -> Result<(), crucible_smf::ScfError>;
fn enable(&self, temporary: bool) -> Result<(), crucible_smf::ScfError>;
#[cfg(test)]
fn enabled(&self) -> bool;

fn get_pg(
Expand Down Expand Up @@ -146,6 +147,7 @@ impl<'a> SmfInstance for RealSmfInstance<'a> {
self.inst.enable(temporary)
}

#[cfg(test)]
fn enabled(&self) -> bool {
unimplemented!();
}
Expand Down Expand Up @@ -355,28 +357,29 @@ impl<'a> SmfTransaction for RealSmfTransaction<'a> {
}

#[derive(Debug)]
#[cfg(test)]
pub struct MockSmf {
scope: String,

// Instance name -> Mock instance entry
config: Mutex<HashMap<String, MockSmfInstance>>,
}

#[cfg(test)]
impl MockSmf {
#[cfg(test)]
pub fn new(scope: String) -> MockSmf {
MockSmf {
scope,
config: Mutex::new(HashMap::new()),
}
}

#[cfg(test)]
pub fn config_is_empty(&self) -> bool {
self.config.lock().unwrap().is_empty()
}
}

#[cfg(test)]
impl PartialEq for MockSmf {
fn eq(&self, other: &Self) -> bool {
let lhs = self.config.lock().unwrap();
Expand All @@ -386,6 +389,7 @@ impl PartialEq for MockSmf {
}
}

#[cfg(test)]
impl SmfInterface for MockSmf {
fn instances(
&self,
Expand Down Expand Up @@ -435,7 +439,6 @@ impl SmfInterface for MockSmf {
/// datafile, disabled stuff remains in the current SMF interface and will
/// cause PartialEq comparison to fail. Prune that here so that comparison
/// can be done.
#[cfg(test)]
fn prune(&self) {
let mut config = self.config.lock().unwrap();
let pairs: Vec<(String, MockSmfInstance)> = config.drain().collect();
Expand Down Expand Up @@ -542,6 +545,7 @@ impl SmfInstance for MockSmfInstance {
Ok(())
}

#[cfg(test)]
fn enabled(&self) -> bool {
self.inner.lock().unwrap().enabled
}
Expand Down
6 changes: 5 additions & 1 deletion agent/src/snapshot_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
use super::model::*;
use anyhow::{bail, Result};
use slog::{error, info, Logger};
#[cfg(test)]
use std::collections::HashSet;
use std::process::Command;
#[cfg(test)]
use std::sync::Mutex;

use chrono::{TimeZone, Utc};
Expand Down Expand Up @@ -201,13 +203,14 @@ impl SnapshotInterface for ZfsSnapshotInterface {
}
}

#[cfg(test)]
pub struct TestSnapshotInterface {
log: Logger,
snapshots: Mutex<HashSet<String>>,
}

#[cfg(test)]
impl TestSnapshotInterface {
#[cfg(test)]
pub fn new(log: Logger) -> TestSnapshotInterface {
TestSnapshotInterface {
log,
Expand All @@ -216,6 +219,7 @@ impl TestSnapshotInterface {
}
}

#[cfg(test)]
impl SnapshotInterface for TestSnapshotInterface {
fn get_snapshots_for_dataset(
&self,
Expand Down
1 change: 1 addition & 0 deletions downstairs/src/extent_inner_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl RawInner {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&path)?;

// All 0s are fine for everything except extent version in the metadata
Expand Down
4 changes: 2 additions & 2 deletions downstairs/src/extent_inner_sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ impl SqliteMoreInner {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&path)?;

file.set_len(size)?;
Expand Down Expand Up @@ -1002,8 +1003,7 @@ impl SqliteMoreInner {
/// unadorned variant should be called instead.
fn truncate_encryption_contexts_and_hashes_with_tx(
&self,
extent_block_indexes_and_hashes: impl Iterator<Item = (usize, u64)>
+ ExactSizeIterator,
extent_block_indexes_and_hashes: impl ExactSizeIterator<Item = (usize, u64)>,
tx: &Transaction,
) -> Result<()> {
let n_blocks = extent_block_indexes_and_hashes.len();
Expand Down
6 changes: 2 additions & 4 deletions downstairs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2023 Oxide Computer Company
#![cfg_attr(usdt_need_asm, feature(asm))]
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]

use futures::lock::Mutex;
use std::cmp::Ordering;
Expand Down Expand Up @@ -2438,7 +2436,7 @@ impl Downstairs {
.unwrap();

let active_upstairs_connection = self.connection_state
[&active_id]
[active_id]
.upstairs_connection()
.expect("bad ConnectionId for active connection");
warn!(
Expand Down Expand Up @@ -2539,7 +2537,7 @@ impl Downstairs {
fn is_active(&self, connection: UpstairsConnection) -> bool {
let uuid = connection.upstairs_id;
if let Some(id) = self.active_upstairs.get(&uuid) {
self.connection_state[&id].upstairs_connection() == Some(connection)
self.connection_state[id].upstairs_connection() == Some(connection)
} else {
false
}
Expand Down
2 changes: 0 additions & 2 deletions downstairs/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2023 Oxide Computer Company
#![cfg_attr(usdt_need_asm, feature(asm))]
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]

use std::net::{IpAddr, SocketAddr};
use std::path::PathBuf;
Expand Down
5 changes: 3 additions & 2 deletions downstairs/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,10 +769,10 @@ impl Region {
integrity_hash(&[
&encryption_context.nonce[..],
&encryption_context.tag[..],
&block,
block,
])
} else {
integrity_hash(&[&block])
integrity_hash(&[block])
};

if computed_hash != ctx.hash {
Expand Down Expand Up @@ -1098,6 +1098,7 @@ impl Region {
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(&copy_path)?;
Ok(file)
}
Expand Down
4 changes: 4 additions & 0 deletions upstairs/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2408,14 +2408,18 @@ pub(crate) enum ClientRunResult {
/// The initial connection timed out
ConnectionTimeout,
/// We failed to make the initial connection
#[allow(dead_code)]
ConnectionFailed(std::io::Error),
/// We experienced a timeout after connecting
Timeout,
/// A socket write failed
#[allow(dead_code)]
WriteFailed(anyhow::Error),
/// We received an error while reading from the connection
#[allow(dead_code)]
ReadFailed(anyhow::Error),
/// The `DownstairsClient` requested that the task stop, so it did
#[allow(dead_code)]
RequestedStop(ClientStopReason),
/// The socket closed cleanly and the task exited
Finished,
Expand Down
5 changes: 1 addition & 4 deletions upstairs/src/downstairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3316,10 +3316,7 @@ impl Downstairs {
ds_id: JobId,
client_id: ClientId,
) -> Option<CrucibleError> {
let Some(job) = self.ds_active.get(&ds_id) else {
return None;
};

let job = self.ds_active.get(&ds_id)?;
let state = &job.state[client_id];

if let IOState::Error(e) = state {
Expand Down
2 changes: 0 additions & 2 deletions upstairs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright 2023 Oxide Computer Company
#![cfg_attr(usdt_need_asm, feature(asm))]
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]
#![allow(clippy::mutex_atomic)]

use std::clone::Clone;
Expand Down
6 changes: 1 addition & 5 deletions upstairs/src/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,7 @@ impl Volume {
if let Some(ref read_only_parent) = self.read_only_parent {
// If requested, setup the pause between IOs as well as an initial
// waiting period before the scrubber starts.
let pause_millis = if let Some(scrub_pause) = scrub_pause {
scrub_pause
} else {
0
};
let pause_millis = scrub_pause.unwrap_or(0);

if let Some(start_delay) = start_delay {
info!(
Expand Down

0 comments on commit 34cb612

Please sign in to comment.