Skip to content

Commit 34cb612

Browse files
authored
clippy lints for rust 1.80.0 (oxidecomputer#1436)
Fixes to clippy lints for toolchain 1.80.0
1 parent ea2282e commit 34cb612

12 files changed

+27
-26
lines changed

agent/src/datafile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl DataFile {
335335
/*
336336
* Look for an existing running snapshot.
337337
*/
338-
if inner.running_snapshots.get(&request.id).is_none() {
338+
if !inner.running_snapshots.contains_key(&request.id) {
339339
bail!("no running snapshots for region {}", request.id.0);
340340
}
341341

agent/src/smf_interface.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub trait SmfInstance {
9393
>;
9494
fn disable(&self, temporary: bool) -> Result<(), crucible_smf::ScfError>;
9595
fn enable(&self, temporary: bool) -> Result<(), crucible_smf::ScfError>;
96+
#[cfg(test)]
9697
fn enabled(&self) -> bool;
9798

9899
fn get_pg(
@@ -146,6 +147,7 @@ impl<'a> SmfInstance for RealSmfInstance<'a> {
146147
self.inst.enable(temporary)
147148
}
148149

150+
#[cfg(test)]
149151
fn enabled(&self) -> bool {
150152
unimplemented!();
151153
}
@@ -355,28 +357,29 @@ impl<'a> SmfTransaction for RealSmfTransaction<'a> {
355357
}
356358

357359
#[derive(Debug)]
360+
#[cfg(test)]
358361
pub struct MockSmf {
359362
scope: String,
360363

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

368+
#[cfg(test)]
365369
impl MockSmf {
366-
#[cfg(test)]
367370
pub fn new(scope: String) -> MockSmf {
368371
MockSmf {
369372
scope,
370373
config: Mutex::new(HashMap::new()),
371374
}
372375
}
373376

374-
#[cfg(test)]
375377
pub fn config_is_empty(&self) -> bool {
376378
self.config.lock().unwrap().is_empty()
377379
}
378380
}
379381

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

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

548+
#[cfg(test)]
545549
fn enabled(&self) -> bool {
546550
self.inner.lock().unwrap().enabled
547551
}

agent/src/snapshot_interface.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
use super::model::*;
44
use anyhow::{bail, Result};
55
use slog::{error, info, Logger};
6+
#[cfg(test)]
67
use std::collections::HashSet;
78
use std::process::Command;
9+
#[cfg(test)]
810
use std::sync::Mutex;
911

1012
use chrono::{TimeZone, Utc};
@@ -201,13 +203,14 @@ impl SnapshotInterface for ZfsSnapshotInterface {
201203
}
202204
}
203205

206+
#[cfg(test)]
204207
pub struct TestSnapshotInterface {
205208
log: Logger,
206209
snapshots: Mutex<HashSet<String>>,
207210
}
208211

212+
#[cfg(test)]
209213
impl TestSnapshotInterface {
210-
#[cfg(test)]
211214
pub fn new(log: Logger) -> TestSnapshotInterface {
212215
TestSnapshotInterface {
213216
log,
@@ -216,6 +219,7 @@ impl TestSnapshotInterface {
216219
}
217220
}
218221

222+
#[cfg(test)]
219223
impl SnapshotInterface for TestSnapshotInterface {
220224
fn get_snapshots_for_dataset(
221225
&self,

downstairs/src/extent_inner_raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ impl RawInner {
529529
.read(true)
530530
.write(true)
531531
.create(true)
532+
.truncate(true)
532533
.open(&path)?;
533534

534535
// All 0s are fine for everything except extent version in the metadata

downstairs/src/extent_inner_sqlite.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ impl SqliteMoreInner {
718718
.read(true)
719719
.write(true)
720720
.create(true)
721+
.truncate(true)
721722
.open(&path)?;
722723

723724
file.set_len(size)?;
@@ -1002,8 +1003,7 @@ impl SqliteMoreInner {
10021003
/// unadorned variant should be called instead.
10031004
fn truncate_encryption_contexts_and_hashes_with_tx(
10041005
&self,
1005-
extent_block_indexes_and_hashes: impl Iterator<Item = (usize, u64)>
1006-
+ ExactSizeIterator,
1006+
extent_block_indexes_and_hashes: impl ExactSizeIterator<Item = (usize, u64)>,
10071007
tx: &Transaction,
10081008
) -> Result<()> {
10091009
let n_blocks = extent_block_indexes_and_hashes.len();

downstairs/src/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Copyright 2023 Oxide Computer Company
2-
#![cfg_attr(usdt_need_asm, feature(asm))]
3-
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]
42

53
use futures::lock::Mutex;
64
use std::cmp::Ordering;
@@ -2438,7 +2436,7 @@ impl Downstairs {
24382436
.unwrap();
24392437

24402438
let active_upstairs_connection = self.connection_state
2441-
[&active_id]
2439+
[active_id]
24422440
.upstairs_connection()
24432441
.expect("bad ConnectionId for active connection");
24442442
warn!(
@@ -2539,7 +2537,7 @@ impl Downstairs {
25392537
fn is_active(&self, connection: UpstairsConnection) -> bool {
25402538
let uuid = connection.upstairs_id;
25412539
if let Some(id) = self.active_upstairs.get(&uuid) {
2542-
self.connection_state[&id].upstairs_connection() == Some(connection)
2540+
self.connection_state[id].upstairs_connection() == Some(connection)
25432541
} else {
25442542
false
25452543
}

downstairs/src/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Copyright 2023 Oxide Computer Company
2-
#![cfg_attr(usdt_need_asm, feature(asm))]
3-
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]
42

53
use std::net::{IpAddr, SocketAddr};
64
use std::path::PathBuf;

downstairs/src/region.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -769,10 +769,10 @@ impl Region {
769769
integrity_hash(&[
770770
&encryption_context.nonce[..],
771771
&encryption_context.tag[..],
772-
&block,
772+
block,
773773
])
774774
} else {
775-
integrity_hash(&[&block])
775+
integrity_hash(&[block])
776776
};
777777

778778
if computed_hash != ctx.hash {
@@ -1098,6 +1098,7 @@ impl Region {
10981098
.read(true)
10991099
.write(true)
11001100
.create(true)
1101+
.truncate(true)
11011102
.open(&copy_path)?;
11021103
Ok(file)
11031104
}

upstairs/src/client.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2408,14 +2408,18 @@ pub(crate) enum ClientRunResult {
24082408
/// The initial connection timed out
24092409
ConnectionTimeout,
24102410
/// We failed to make the initial connection
2411+
#[allow(dead_code)]
24112412
ConnectionFailed(std::io::Error),
24122413
/// We experienced a timeout after connecting
24132414
Timeout,
24142415
/// A socket write failed
2416+
#[allow(dead_code)]
24152417
WriteFailed(anyhow::Error),
24162418
/// We received an error while reading from the connection
2419+
#[allow(dead_code)]
24172420
ReadFailed(anyhow::Error),
24182421
/// The `DownstairsClient` requested that the task stop, so it did
2422+
#[allow(dead_code)]
24192423
RequestedStop(ClientStopReason),
24202424
/// The socket closed cleanly and the task exited
24212425
Finished,

upstairs/src/downstairs.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3316,10 +3316,7 @@ impl Downstairs {
33163316
ds_id: JobId,
33173317
client_id: ClientId,
33183318
) -> Option<CrucibleError> {
3319-
let Some(job) = self.ds_active.get(&ds_id) else {
3320-
return None;
3321-
};
3322-
3319+
let job = self.ds_active.get(&ds_id)?;
33233320
let state = &job.state[client_id];
33243321

33253322
if let IOState::Error(e) = state {

upstairs/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
// Copyright 2023 Oxide Computer Company
2-
#![cfg_attr(usdt_need_asm, feature(asm))]
3-
#![cfg_attr(all(target_os = "macos", usdt_need_asm_sym), feature(asm_sym))]
42
#![allow(clippy::mutex_atomic)]
53

64
use std::clone::Clone;

upstairs/src/volume.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ impl Volume {
378378
if let Some(ref read_only_parent) = self.read_only_parent {
379379
// If requested, setup the pause between IOs as well as an initial
380380
// waiting period before the scrubber starts.
381-
let pause_millis = if let Some(scrub_pause) = scrub_pause {
382-
scrub_pause
383-
} else {
384-
0
385-
};
381+
let pause_millis = scrub_pause.unwrap_or(0);
386382

387383
if let Some(start_delay) = start_delay {
388384
info!(

0 commit comments

Comments
 (0)