Skip to content

Commit 1d61739

Browse files
committed
Fix clippy warnings
Mostly mechanical fixes: removing needless borrows, adding lifetime annotations, using modern numeric constants (i32::MAX), and suppressing warnings for dropshot-generated dead code. Notable equivalences: - .as_bytes().len() to .len() on String: both return byte count - .trim().split_whitespace() to .split_whitespace(): split_whitespace already skips leading/trailing whitespace - .into_iter() to .iter() on slices: both yield &T
1 parent cc723d4 commit 1d61739

File tree

28 files changed

+73
-73
lines changed

28 files changed

+73
-73
lines changed

agent/src/control/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ async fn cmd_address_list(mut l: Level<Stuff>) -> Result<()> {
178178
let mut r = Row::default();
179179

180180
r.add_str("name", &addr.name);
181-
r.add_str("cidr", &net.to_string());
182-
r.add_str("first", &first.to_string());
183-
r.add_str("last", &last.to_string());
181+
r.add_str("cidr", net.to_string());
182+
r.add_str("first", first.to_string());
183+
r.add_str("last", last.to_string());
184184
r.add_u64("count", addr.count.into());
185185
r.add_str("family", "inet");
186-
r.add_str("network", &net.network().to_string());
187-
r.add_str("mask", &net.netmask().to_string());
186+
r.add_str("network", net.network().to_string());
187+
r.add_str("mask", net.netmask().to_string());
188188
r.add_str("routed", if addr.routed { "yes" } else { "no" });
189189
r.add_str("gateway", addr.gateway.as_deref().unwrap_or("-"));
190190

agent/src/exec.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ fn spawn_reader<T>(
2323
where
2424
T: Read + Send + 'static,
2525
{
26-
let stream = match stream {
27-
Some(stream) => stream,
28-
None => return None,
29-
};
26+
let stream = stream?;
3027

3128
Some(std::thread::spawn(move || {
3229
let mut r = BufReader::new(stream);
@@ -297,7 +294,7 @@ fn run_common(
297294
* process.
298295
*/
299296
if ab.bgproc.is_none() {
300-
tx.blocking_send(ab.exit(&start, &end, std::i32::MAX))
297+
tx.blocking_send(ab.exit(&start, &end, i32::MAX))
301298
.unwrap();
302299
}
303300

@@ -332,7 +329,7 @@ fn run_common(
332329
let code = if let Some(code) = es.code() {
333330
code
334331
} else {
335-
std::i32::MAX
332+
i32::MAX
336333
};
337334
tx.blocking_send(ab.exit(&start, &end, code)).unwrap();
338335
stdio_warning

agent/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ async fn cmd_install(mut l: Level<Agent>) -> Result<()> {
10931093
let status = Command::new("/sbin/zfs")
10941094
.arg("create")
10951095
.arg("-o")
1096-
.arg(&format!("mountpoint={}", INPUT_PATH))
1096+
.arg(format!("mountpoint={}", INPUT_PATH))
10971097
.arg(INPUT_DATASET)
10981098
.env_clear()
10991099
.current_dir("/")

bin/src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ mod config;
2626

2727
trait FlagsExt {
2828
#[must_use]
29-
fn add_flags(&mut self, name: &'static str) -> Flags;
29+
fn add_flags(&mut self, name: &'static str) -> Flags<'_>;
3030
}
3131

3232
impl FlagsExt for Row {
33-
fn add_flags(&mut self, name: &'static str) -> Flags {
33+
fn add_flags(&mut self, name: &'static str) -> Flags<'_> {
3434
Flags { row: self, name, out: String::new() }
3535
}
3636
}
@@ -1226,7 +1226,7 @@ async fn do_job_store_list(mut l: Level<Stuff>) -> Result<()> {
12261226
);
12271227
r.add_str(
12281228
"updated",
1229-
&ent.time_update.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
1229+
ent.time_update.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
12301230
);
12311231

12321232
t.add_row(r);
@@ -1351,7 +1351,7 @@ async fn do_user_list(mut l: Level<Stuff>) -> Result<()> {
13511351
r.add_str("name", &u.name);
13521352
r.add_str(
13531353
"creation",
1354-
&u.time_create.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
1354+
u.time_create.to_rfc3339_opts(chrono::SecondsFormat::Secs, true),
13551355
);
13561356
r.add_age("age", u.time_create.age());
13571357
t.add_row(r);

download/src/kinds/url.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const BUF_COUNT: usize = 10;
2727
* assessed against the actual file size and a partial (206) response will be
2828
* returned, for both GET and HEAD.
2929
*/
30+
#[allow(clippy::too_many_arguments)]
3031
pub async fn stream_from_url(
3132
log: &Logger,
3233
info: String,

download/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn make_get_response<E>(
4343
rx: mpsc::Receiver<std::result::Result<Frame<Bytes>, E>>,
4444
) -> Result<Response<Body>>
4545
where
46-
E: Into<Box<(dyn std::error::Error + Send + Sync + 'static)>>
46+
E: Into<Box<dyn std::error::Error + Send + Sync + 'static>>
4747
+ Send
4848
+ Sync
4949
+ 'static,

factory/aws/src/aws.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Instance {
7070
.try_into()
7171
.unwrap();
7272

73-
(if when <= now { now - when } else { 0 }) / 1000
73+
now.saturating_sub(when) / 1000
7474
})
7575
.unwrap_or(0)
7676
}
@@ -188,7 +188,7 @@ async fn create_instance(
188188

189189
let mut instances = res
190190
.instances()
191-
.into_iter()
191+
.iter()
192192
.map(|i| Instance::from((i, config.aws.tag.as_str())))
193193
.collect::<Vec<_>>();
194194

@@ -218,13 +218,12 @@ async fn instances(
218218
Ok(res
219219
.reservations()
220220
.iter()
221-
.map(|r| {
221+
.flat_map(|r| {
222222
r.instances().iter().map(|i| {
223223
let i = Instance::from((i, tag));
224224
(i.id.to_string(), i)
225225
})
226226
})
227-
.flatten()
228227
.collect())
229228
}
230229

@@ -421,7 +420,7 @@ async fn aws_worker_one(
421420
* There is a record of a particular instance ID for this worker.
422421
* Check to see if that instance exists.
423422
*/
424-
if let Some(i) = insts.get(&instance_id.to_string()) {
423+
if let Some(i) = insts.get(instance_id) {
425424
if i.state == "terminated" {
426425
/*
427426
* The instance exists, but is terminated. Delete the

factory/aws/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Central {
7272
* Allow the per-target diagnostic configuration to override the base
7373
* diagnostic configuration.
7474
*/
75-
Ok(self.config.diag.apply_overrides(&t.diag).build()?)
75+
self.config.diag.apply_overrides(&t.diag).build()
7676
}
7777
}
7878

factory/gimlet/src/cleanup.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn setup() -> Result<()> {
110110
bail!("giving up after {MAX_TIME} seconds");
111111
}
112112

113-
if let Ok(st) = svcs(&fmri) {
113+
if let Ok(st) = svcs(fmri) {
114114
if st.next.is_none() && st.current == "ON" {
115115
println!(" * {fmri} now online!");
116116
break;
@@ -125,7 +125,7 @@ pub fn setup() -> Result<()> {
125125
* only be one!
126126
*/
127127
let pools = zpool_unimported_list()?;
128-
if pools.len() == 0 {
128+
if pools.is_empty() {
129129
bail!("no unimported pool found!");
130130
} else if pools.len() > 1 {
131131
bail!("more than one unimported pool found!");
@@ -137,14 +137,14 @@ pub fn setup() -> Result<()> {
137137
};
138138

139139
println!(" * importing pool {pool:?}...");
140-
zpool_import(&pool)?;
140+
zpool_import(pool)?;
141141

142142
/*
143143
* Update the BSU symlink:
144144
*/
145145
std::fs::create_dir_all("/pool/bsu")?;
146146
std::fs::remove_file("/pool/bsu/0").ok();
147-
std::os::unix::fs::symlink(&format!("../int/{pool_id}"), "/pool/bsu/0")?;
147+
std::os::unix::fs::symlink(format!("../int/{pool_id}"), "/pool/bsu/0")?;
148148

149149
/*
150150
* Create the swap device:
@@ -252,14 +252,14 @@ fn prepare_m2() -> Result<()> {
252252
let p = &mut vtoc.parts_mut()[i];
253253
p.p_tag = efi::sys::V_USR;
254254
p.p_start = next_start;
255-
p.p_size = size.into();
255+
p.p_size = size;
256256
next_start = next_start.checked_add(size).unwrap();
257257
}
258258

259259
/*
260260
* Create the dump slice:
261261
*/
262-
let size = (1 * 1024 * 1024 * 1024 * 1024) / vtoc.block_size();
262+
let size = (1024 * 1024 * 1024 * 1024) / vtoc.block_size();
263263
let p = &mut vtoc.parts_mut()[4];
264264
p.p_tag = efi::sys::V_USR;
265265
p.p_start = next_start;
@@ -287,11 +287,11 @@ fn prepare_m2() -> Result<()> {
287287
.env_clear()
288288
.arg("create")
289289
.arg("-O")
290-
.arg(&format!("mountpoint=/pool/int/{id}"))
290+
.arg(format!("mountpoint=/pool/int/{id}"))
291291
.arg("-O")
292292
.arg("compress=on")
293293
.arg(&pool)
294-
.arg(&format!("{}s5", d.name))
294+
.arg(format!("{}s5", d.name))
295295
.output()?;
296296

297297
if !out.status.success() {

factory/gimlet/src/disks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn list_disks() -> Result<Disks> {
121121
slice: u32|
122122
-> Result<Option<devinfo::DevLink>> {
123123
let mut paths = links
124-
.links_for_path(&device)?
124+
.links_for_path(device)?
125125
.into_iter()
126126
.filter(|l| {
127127
l.linktype() == devinfo::DevLinkType::Primary
@@ -193,18 +193,18 @@ pub fn list_disks() -> Result<Disks> {
193193
*/
194194
let device = m.devfs_path()?;
195195

196-
Ok((0..=8)
196+
(0..=8)
197197
.map(|num| {
198198
Ok(slice_from_path(&device, num)?.map(|link| {
199199
(num, m.spec_type(), link.path().to_owned())
200200
}))
201201
})
202-
.collect::<Result<Vec<_>>>()?)
202+
.collect::<Result<Vec<_>>>()
203203
})
204204
.collect::<Result<Vec<_>>>()?
205205
.into_iter()
206206
.flatten()
207-
.filter_map(|v| v)
207+
.flatten()
208208
.collect::<Vec<_>>();
209209

210210
/*

0 commit comments

Comments
 (0)