Skip to content

Commit c5e5794

Browse files
ShadowCurseroypat
andcommitted
chore(clippy): update code with new lints
From: Egor Lazarchuk <yegorlz@amazon.co.uk> With a new Rust version, new Clippy entered our repository. This commit aligns our codebase with guidance provided by new lints. Also remove a `deny(clippy::pedantic)`, because I'm not fixing those. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk> Co-authored-by: Patrick Roy <roypat@amazon.co.uk> Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
1 parent 68b7c99 commit c5e5794

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+128
-155
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ resolver = "2"
99

1010
[workspace.lints.rust]
1111
missing_debug_implementations = "warn"
12+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] }
1213

1314
[workspace.lints.clippy]
1415
ptr_as_ptr = "warn"

src/acpi-tables/src/aml.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub struct Package<'a> {
180180
children: Vec<&'a dyn Aml>,
181181
}
182182

183-
impl<'a> Aml for Package<'a> {
183+
impl Aml for Package<'_> {
184184
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
185185
let mut tmp = vec![self.children.len().try_into().unwrap()];
186186
for child in &self.children {
@@ -336,7 +336,7 @@ pub struct ResourceTemplate<'a> {
336336
children: Vec<&'a dyn Aml>,
337337
}
338338

339-
impl<'a> Aml for ResourceTemplate<'a> {
339+
impl Aml for ResourceTemplate<'_> {
340340
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
341341
let mut tmp = Vec::new();
342342
// Add buffer data
@@ -607,7 +607,7 @@ pub struct Device<'a> {
607607
children: Vec<&'a dyn Aml>,
608608
}
609609

610-
impl<'a> Aml for Device<'a> {
610+
impl Aml for Device<'_> {
611611
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
612612
let mut tmp = Vec::new();
613613
self.path.append_aml_bytes(&mut tmp)?;
@@ -637,7 +637,7 @@ pub struct Scope<'a> {
637637
children: Vec<&'a dyn Aml>,
638638
}
639639

640-
impl<'a> Aml for Scope<'a> {
640+
impl Aml for Scope<'_> {
641641
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
642642
let mut tmp = Vec::new();
643643
self.path.append_aml_bytes(&mut tmp)?;
@@ -678,7 +678,7 @@ impl<'a> Method<'a> {
678678
}
679679
}
680680

681-
impl<'a> Aml for Method<'a> {
681+
impl Aml for Method<'_> {
682682
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
683683
let mut tmp = Vec::new();
684684
self.path.append_aml_bytes(&mut tmp)?;
@@ -707,7 +707,7 @@ impl<'a> Return<'a> {
707707
}
708708
}
709709

710-
impl<'a> Aml for Return<'a> {
710+
impl Aml for Return<'_> {
711711
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
712712
bytes.push(0xa4); // ReturnOp
713713
self.value.append_aml_bytes(bytes)?;
@@ -850,7 +850,7 @@ impl<'a> If<'a> {
850850
}
851851
}
852852

853-
impl<'a> Aml for If<'a> {
853+
impl Aml for If<'_> {
854854
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
855855
let mut tmp = Vec::new();
856856
self.predicate.append_aml_bytes(&mut tmp)?;
@@ -878,7 +878,7 @@ impl<'a> Equal<'a> {
878878
}
879879
}
880880

881-
impl<'a> Aml for Equal<'a> {
881+
impl Aml for Equal<'_> {
882882
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
883883
bytes.push(0x93); // LEqualOp
884884
self.left.append_aml_bytes(bytes)?;
@@ -898,7 +898,7 @@ impl<'a> LessThan<'a> {
898898
}
899899
}
900900

901-
impl<'a> Aml for LessThan<'a> {
901+
impl Aml for LessThan<'_> {
902902
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
903903
bytes.push(0x95); // LLessOp
904904
self.left.append_aml_bytes(bytes)?;
@@ -942,7 +942,7 @@ impl<'a> Store<'a> {
942942
}
943943
}
944944

945-
impl<'a> Aml for Store<'a> {
945+
impl Aml for Store<'_> {
946946
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
947947
bytes.push(0x70); // StoreOp
948948
self.value.append_aml_bytes(bytes)?;
@@ -1023,7 +1023,7 @@ impl<'a> Notify<'a> {
10231023
}
10241024
}
10251025

1026-
impl<'a> Aml for Notify<'a> {
1026+
impl Aml for Notify<'_> {
10271027
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
10281028
bytes.push(0x86); // NotifyOp
10291029
self.object.append_aml_bytes(bytes)?;
@@ -1046,7 +1046,7 @@ impl<'a> While<'a> {
10461046
}
10471047
}
10481048

1049-
impl<'a> Aml for While<'a> {
1049+
impl Aml for While<'_> {
10501050
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
10511051
let mut tmp = Vec::new();
10521052
self.predicate.append_aml_bytes(&mut tmp)?;
@@ -1116,7 +1116,7 @@ impl<'a> MethodCall<'a> {
11161116
}
11171117
}
11181118

1119-
impl<'a> Aml for MethodCall<'a> {
1119+
impl Aml for MethodCall<'_> {
11201120
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
11211121
self.name.append_aml_bytes(bytes)?;
11221122
for arg in self.args.iter() {
@@ -1169,7 +1169,7 @@ impl<'a, T> CreateField<'a, T> {
11691169
}
11701170
}
11711171

1172-
impl<'a> Aml for CreateField<'a, u64> {
1172+
impl Aml for CreateField<'_, u64> {
11731173
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
11741174
bytes.push(0x8f); // CreateQWordFieldOp
11751175
self.buffer.append_aml_bytes(bytes)?;
@@ -1178,7 +1178,7 @@ impl<'a> Aml for CreateField<'a, u64> {
11781178
}
11791179
}
11801180

1181-
impl<'a> Aml for CreateField<'a, u32> {
1181+
impl Aml for CreateField<'_, u32> {
11821182
fn append_aml_bytes(&self, bytes: &mut Vec<u8>) -> Result<(), AmlError> {
11831183
bytes.push(0x8a); // CreateDWordFieldOp
11841184
self.buffer.append_aml_bytes(bytes)?;

src/clippy-tracing/src/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
#![warn(clippy::pedantic)]
5-
64
//! A tool to add, remove and check for `tracing::instrument` in large projects where it is
75
//! infeasible to manually add it to thousands of functions.
86

src/firecracker/src/api_server/request/actions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ struct ActionBody {
3030

3131
pub(crate) fn parse_put_actions(body: &Body) -> Result<ParsedRequest, RequestError> {
3232
METRICS.put_api_requests.actions_count.inc();
33-
let action_body = serde_json::from_slice::<ActionBody>(body.raw()).map_err(|err| {
33+
let action_body = serde_json::from_slice::<ActionBody>(body.raw()).inspect_err(|_| {
3434
METRICS.put_api_requests.actions_fails.inc();
35-
err
3635
})?;
3736

3837
match action_body.action_type {

src/firecracker/src/api_server/request/boot_source.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use super::Body;
1111
pub(crate) fn parse_put_boot_source(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.boot_source_count.inc();
1313
Ok(ParsedRequest::new_sync(VmmAction::ConfigureBootSource(
14-
serde_json::from_slice::<BootSourceConfig>(body.raw()).map_err(|err| {
14+
serde_json::from_slice::<BootSourceConfig>(body.raw()).inspect_err(|_| {
1515
METRICS.put_api_requests.boot_source_fails.inc();
16-
err
1716
})?,
1817
)))
1918
}

src/firecracker/src/api_server/request/drive.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub(crate) fn parse_put_drive(
2020
return Err(RequestError::EmptyID);
2121
};
2222

23-
let device_cfg = serde_json::from_slice::<BlockDeviceConfig>(body.raw()).map_err(|err| {
23+
let device_cfg = serde_json::from_slice::<BlockDeviceConfig>(body.raw()).inspect_err(|_| {
2424
METRICS.put_api_requests.drive_fails.inc();
25-
err
2625
})?;
2726

2827
if id != device_cfg.drive_id {
@@ -51,9 +50,8 @@ pub(crate) fn parse_patch_drive(
5150
};
5251

5352
let block_device_update_cfg: BlockDeviceUpdateConfig =
54-
serde_json::from_slice::<BlockDeviceUpdateConfig>(body.raw()).map_err(|err| {
53+
serde_json::from_slice::<BlockDeviceUpdateConfig>(body.raw()).inspect_err(|_| {
5554
METRICS.patch_api_requests.drive_fails.inc();
56-
err
5755
})?;
5856

5957
if id != block_device_update_cfg.drive_id {

src/firecracker/src/api_server/request/logger.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use super::Body;
1010
pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, RequestError> {
1111
METRICS.put_api_requests.logger_count.inc();
1212
let res = serde_json::from_slice::<vmm::logger::LoggerConfig>(body.raw());
13-
let config = res.map_err(|err| {
13+
let config = res.inspect_err(|_| {
1414
METRICS.put_api_requests.logger_fails.inc();
15-
err
1615
})?;
1716
Ok(ParsedRequest::new_sync(VmmAction::ConfigureLogger(config)))
1817
}

src/firecracker/src/api_server/request/machine_configuration.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ pub(crate) fn parse_get_machine_config() -> Result<ParsedRequest, RequestError>
1515

1616
pub(crate) fn parse_put_machine_config(body: &Body) -> Result<ParsedRequest, RequestError> {
1717
METRICS.put_api_requests.machine_cfg_count.inc();
18-
let config = serde_json::from_slice::<MachineConfig>(body.raw()).map_err(|err| {
18+
let config = serde_json::from_slice::<MachineConfig>(body.raw()).inspect_err(|_| {
1919
METRICS.put_api_requests.machine_cfg_fails.inc();
20-
err
2120
})?;
2221

2322
// Check for the presence of deprecated `cpu_template` field.
@@ -44,9 +43,8 @@ pub(crate) fn parse_put_machine_config(body: &Body) -> Result<ParsedRequest, Req
4443
pub(crate) fn parse_patch_machine_config(body: &Body) -> Result<ParsedRequest, RequestError> {
4544
METRICS.patch_api_requests.machine_cfg_count.inc();
4645
let config_update =
47-
serde_json::from_slice::<MachineConfigUpdate>(body.raw()).map_err(|err| {
46+
serde_json::from_slice::<MachineConfigUpdate>(body.raw()).inspect_err(|_| {
4847
METRICS.patch_api_requests.machine_cfg_fails.inc();
49-
err
5048
})?;
5149

5250
if config_update.is_empty() {

src/firecracker/src/api_server/request/metrics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use super::Body;
1111
pub(crate) fn parse_put_metrics(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.metrics_count.inc();
1313
Ok(ParsedRequest::new_sync(VmmAction::ConfigureMetrics(
14-
serde_json::from_slice::<MetricsConfig>(body.raw()).map_err(|err| {
14+
serde_json::from_slice::<MetricsConfig>(body.raw()).inspect_err(|_| {
1515
METRICS.put_api_requests.metrics_fails.inc();
16-
err
1716
})?,
1817
)))
1918
}

src/firecracker/src/api_server/request/mmds.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ pub(crate) fn parse_get_mmds() -> Result<ParsedRequest, RequestError> {
1616
}
1717

1818
fn parse_put_mmds_config(body: &Body) -> Result<ParsedRequest, RequestError> {
19-
let config: MmdsConfig = serde_json::from_slice(body.raw()).map_err(|err| {
19+
let config: MmdsConfig = serde_json::from_slice(body.raw()).inspect_err(|_| {
2020
METRICS.put_api_requests.mmds_fails.inc();
21-
err
2221
})?;
2322
// Construct the `ParsedRequest` object.
2423
let version = config.version;
@@ -42,9 +41,8 @@ pub(crate) fn parse_put_mmds(
4241
METRICS.put_api_requests.mmds_count.inc();
4342
match path_second_token {
4443
None => Ok(ParsedRequest::new_sync(VmmAction::PutMMDS(
45-
serde_json::from_slice(body.raw()).map_err(|err| {
44+
serde_json::from_slice(body.raw()).inspect_err(|_| {
4645
METRICS.put_api_requests.mmds_fails.inc();
47-
err
4846
})?,
4947
))),
5048
Some("config") => parse_put_mmds_config(body),
@@ -61,9 +59,8 @@ pub(crate) fn parse_put_mmds(
6159
pub(crate) fn parse_patch_mmds(body: &Body) -> Result<ParsedRequest, RequestError> {
6260
METRICS.patch_api_requests.mmds_count.inc();
6361
Ok(ParsedRequest::new_sync(VmmAction::PatchMMDS(
64-
serde_json::from_slice(body.raw()).map_err(|err| {
62+
serde_json::from_slice(body.raw()).inspect_err(|_| {
6563
METRICS.patch_api_requests.mmds_fails.inc();
66-
err
6764
})?,
6865
)))
6966
}

src/firecracker/src/api_server/request/net.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub(crate) fn parse_put_net(
2020
return Err(RequestError::EmptyID);
2121
};
2222

23-
let netif = serde_json::from_slice::<NetworkInterfaceConfig>(body.raw()).map_err(|err| {
23+
let netif = serde_json::from_slice::<NetworkInterfaceConfig>(body.raw()).inspect_err(|_| {
2424
METRICS.put_api_requests.network_fails.inc();
25-
err
2625
})?;
2726
if id != netif.iface_id.as_str() {
2827
METRICS.put_api_requests.network_fails.inc();
@@ -53,9 +52,8 @@ pub(crate) fn parse_patch_net(
5352
};
5453

5554
let netif =
56-
serde_json::from_slice::<NetworkInterfaceUpdateConfig>(body.raw()).map_err(|err| {
55+
serde_json::from_slice::<NetworkInterfaceUpdateConfig>(body.raw()).inspect_err(|_| {
5756
METRICS.patch_api_requests.network_fails.inc();
58-
err
5957
})?;
6058
if id != netif.iface_id {
6159
METRICS.patch_api_requests.network_count.inc();

src/firecracker/src/api_server/request/vsock.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use super::Body;
1010

1111
pub(crate) fn parse_put_vsock(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.vsock_count.inc();
13-
let vsock_cfg = serde_json::from_slice::<VsockDeviceConfig>(body.raw()).map_err(|err| {
13+
let vsock_cfg = serde_json::from_slice::<VsockDeviceConfig>(body.raw()).inspect_err(|_| {
1414
METRICS.put_api_requests.vsock_fails.inc();
15-
err
1615
})?;
1716

1817
// Check for the presence of deprecated `vsock_id` field.

src/seccompiler/src/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ mod tests {
868868
}
869869

870870
impl SeccompCondition {
871-
// Creates a new `SeccompCondition`.
871+
/// Creates a new `SeccompCondition`.
872872
pub fn new(
873873
arg_number: u8,
874874
arg_len: SeccompCmpArgLen,

src/seccompiler/src/compiler.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ mod tests {
258258
};
259259

260260
impl Filter {
261-
pub fn new(
261+
fn new(
262262
default_action: SeccompAction,
263263
filter_action: SeccompAction,
264264
filter: Vec<SyscallRule>,
@@ -272,7 +272,7 @@ mod tests {
272272
}
273273

274274
impl SyscallRule {
275-
pub fn new(syscall: String, conditions: Option<Vec<Cond>>) -> SyscallRule {
275+
fn new(syscall: String, conditions: Option<Vec<Cond>>) -> SyscallRule {
276276
SyscallRule {
277277
syscall,
278278
conditions,

src/vmm/benches/queue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn queue_benchmark(c: &mut Criterion) {
8888
for i in 0_u16..16_u16 {
8989
let index = std::hint::black_box(i);
9090
let len = std::hint::black_box(i + 1);
91-
_ = queue.add_used(index as u16, len as u32);
91+
_ = queue.add_used(index, len as u32);
9292
}
9393
})
9494
});
@@ -100,7 +100,7 @@ pub fn queue_benchmark(c: &mut Criterion) {
100100
for i in 0_u16..256_u16 {
101101
let index = std::hint::black_box(i);
102102
let len = std::hint::black_box(i + 1);
103-
_ = queue.add_used(index as u16, len as u32);
103+
_ = queue.add_used(index, len as u32);
104104
}
105105
})
106106
});

src/vmm/src/acpi/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct AcpiTableWriter<'a> {
4848
resource_allocator: &'a mut ResourceAllocator,
4949
}
5050

51-
impl<'a> AcpiTableWriter<'a> {
51+
impl AcpiTableWriter<'_> {
5252
/// Write a table in guest memory
5353
///
5454
/// This will allocate enough space inside guest memory and write the table in the allocated
@@ -181,7 +181,7 @@ pub(crate) fn create_acpi_tables(
181181
}
182182

183183
#[cfg(test)]
184-
pub mod tests {
184+
mod tests {
185185
use acpi_tables::Sdt;
186186
use vm_memory::Bytes;
187187

src/vmm/src/arch/x86_64/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8-
/// Magic addresses externally used to lay out x86_64 VMs.
8+
//! Magic addresses externally used to lay out x86_64 VMs.
99
1010
/// Initial stack for the boot CPU.
1111
pub const BOOT_STACK_POINTER: u64 = 0x8ff0;

src/vmm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ pub(crate) fn set_stdout_nonblocking() {
10231023
}
10241024

10251025
#[cfg(test)]
1026-
pub mod tests {
1026+
pub(crate) mod tests {
10271027
use std::io::Write;
10281028

10291029
use linux_loader::cmdline::Cmdline;

src/vmm/src/cpu_config/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pub mod x86_64;
1515
pub mod aarch64;
1616

1717
#[cfg(test)]
18-
pub mod test_utils;
18+
pub(crate) mod test_utils;

0 commit comments

Comments
 (0)