Skip to content

Commit baa427f

Browse files
roypatdianpopa
authored andcommitted
chore: appease clippy
- The `Default` trait can now be derived - Lifetime elision got more sophisticated Signed-off-by: Patrick Roy <[email protected]>
1 parent 56dfb54 commit baa427f

File tree

9 files changed

+22
-60
lines changed

9 files changed

+22
-60
lines changed

src/devices/src/virtio/block/device.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,18 @@ use super::{io as block_io, Error, CONFIG_SPACE_SIZE, QUEUE_SIZES, SECTOR_SHIFT,
3333
use crate::virtio::{IrqTrigger, IrqType};
3434

3535
/// Configuration options for disk caching.
36-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
36+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
3737
pub enum CacheType {
3838
/// Flushing mechanic will be advertised to the guest driver, but
3939
/// the operation will be a noop.
40+
#[default]
4041
Unsafe,
4142
/// Flushing mechanic will be advertised to the guest driver and
4243
/// flush requests coming from the guest will be performed using
4344
/// `fsync`.
4445
Writeback,
4546
}
4647

47-
impl Default for CacheType {
48-
fn default() -> CacheType {
49-
CacheType::Unsafe
50-
}
51-
}
52-
5348
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
5449
pub enum FileEngineType {
5550
/// Use an Async engine, based on io_uring.

src/devices/src/virtio/block/persist.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ impl From<CacheTypeState> for CacheType {
4646
}
4747
}
4848

49-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Versionize)]
49+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Versionize)]
5050
// NOTICE: Any changes to this structure require a snapshot version bump.
5151
pub enum FileEngineTypeState {
52+
// If the snap version does not contain the `FileEngineType`, it must have been snapshotted
53+
// on a VM using the Sync backend.
54+
#[default]
5255
Sync,
5356
Async,
5457
}
@@ -71,14 +74,6 @@ impl From<FileEngineTypeState> for FileEngineType {
7174
}
7275
}
7376

74-
impl Default for FileEngineTypeState {
75-
fn default() -> Self {
76-
// If the snap version does not contain the `FileEngineType`, it must have been snapshotted
77-
// on a VM using the Sync backend.
78-
FileEngineTypeState::Sync
79-
}
80-
}
81-
8277
#[derive(Clone, Versionize)]
8378
// NOTICE: Any changes to this structure require a snapshot version bump.
8479
pub struct BlockState {

src/devices/src/virtio/queue.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl Queue {
286286
}
287287

288288
/// Pop the first available descriptor chain from the avail ring.
289-
pub fn pop<'a, 'b>(&'a mut self, mem: &'b GuestMemoryMmap) -> Option<DescriptorChain<'b>> {
289+
pub fn pop<'b>(&mut self, mem: &'b GuestMemoryMmap) -> Option<DescriptorChain<'b>> {
290290
let len = self.len(mem);
291291
// The number of descriptor chain heads to process should always
292292
// be smaller or equal to the queue size, as the driver should
@@ -310,8 +310,8 @@ impl Queue {
310310

311311
/// Try to pop the first available descriptor chain from the avail ring.
312312
/// If no descriptor is available, enable notifications.
313-
pub fn pop_or_enable_notification<'a, 'b>(
314-
&'a mut self,
313+
pub fn pop_or_enable_notification<'b>(
314+
&mut self,
315315
mem: &'b GuestMemoryMmap,
316316
) -> Option<DescriptorChain<'b>> {
317317
if !self.uses_notif_suppression {
@@ -330,10 +330,7 @@ impl Queue {
330330
/// # Important
331331
/// This is an internal method that ASSUMES THAT THERE ARE AVAILABLE DESCRIPTORS. Otherwise it
332332
/// will retrieve a descriptor that contains garbage data (obsolete/empty).
333-
fn do_pop_unchecked<'a, 'b>(
334-
&'a mut self,
335-
mem: &'b GuestMemoryMmap,
336-
) -> Option<DescriptorChain<'b>> {
333+
fn do_pop_unchecked<'b>(&mut self, mem: &'b GuestMemoryMmap) -> Option<DescriptorChain<'b>> {
337334
// This fence ensures all subsequent reads see the updated driver writes.
338335
fence(Ordering::Acquire);
339336

src/dumbo/src/tcp/handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,8 @@ mod tests {
507507
use crate::pdu::bytes::NetworkBytesMut;
508508
use crate::tcp::tests::mock_callback;
509509

510-
fn inner_tcp_mut<'a, 'b, T: NetworkBytesMut>(
511-
p: &'a mut IPv4Packet<'b, T>,
510+
fn inner_tcp_mut<'a, T: NetworkBytesMut>(
511+
p: &'a mut IPv4Packet<'_, T>,
512512
) -> TcpSegment<'a, &'a mut [u8]> {
513513
TcpSegment::from_bytes(p.payload_mut(), None).unwrap()
514514
}

src/mmds/src/data_store.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,13 @@ pub struct Mmds {
1919
}
2020

2121
/// MMDS version.
22-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
22+
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
2323
pub enum MmdsVersion {
24+
#[default]
2425
V1,
2526
V2,
2627
}
2728

28-
impl Default for MmdsVersion {
29-
fn default() -> Self {
30-
MmdsVersion::V1
31-
}
32-
}
33-
3429
impl Display for MmdsVersion {
3530
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
3631
match self {

src/vmm/src/vmm_config/instance_info.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,17 @@ use std::fmt::{self, Display, Formatter};
55
use serde::{ser, Serialize};
66

77
/// Enumerates microVM runtime states.
8-
#[derive(Clone, Debug, PartialEq, Eq)]
8+
#[derive(Clone, Debug, Default, PartialEq, Eq)]
99
pub enum VmState {
1010
/// Vm not started (yet)
11+
#[default]
1112
NotStarted,
1213
/// Vm is Paused
1314
Paused,
1415
/// Vm is running
1516
Running,
1617
}
1718

18-
impl Default for VmState {
19-
fn default() -> VmState {
20-
VmState::NotStarted
21-
}
22-
}
23-
2419
impl Display for VmState {
2520
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
2621
match *self {

src/vmm/src/vmm_config/logger.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ use super::{open_file_nonblock, FcLineWriter};
1212
use crate::vmm_config::instance_info::InstanceInfo;
1313

1414
/// Enum used for setting the log level.
15-
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
15+
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
1616
pub enum LoggerLevel {
1717
/// When the level is set to `Error`, the logger will only contain entries
1818
/// that come from the `error` macro.
1919
Error,
2020
/// When the level is set to `Warning`, the logger will only contain entries
2121
/// that come from the `error` and `warn` macros.
22+
#[default]
2223
Warning,
2324
/// When the level is set to `Info`, the logger will only contain entries
2425
/// that come from the `error`, `warn` and `info` macros.
@@ -41,12 +42,6 @@ impl LoggerLevel {
4142
}
4243
}
4344

44-
impl Default for LoggerLevel {
45-
fn default() -> LoggerLevel {
46-
LoggerLevel::Warning
47-
}
48-
}
49-
5045
impl From<LoggerLevel> for LevelFilter {
5146
fn from(logger_level: LoggerLevel) -> Self {
5247
match logger_level {

src/vmm/src/vmm_config/machine_config.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ where
238238

239239
/// Template types available for configuring the CPU features that map
240240
/// to EC2 instances.
241-
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, Versionize)]
241+
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, PartialEq, Serialize, Versionize)]
242242
pub enum CpuFeaturesTemplate {
243243
/// C3 Template.
244244
C3,
@@ -247,6 +247,7 @@ pub enum CpuFeaturesTemplate {
247247
/// T2S Template.
248248
T2S,
249249
/// No CPU template is used.
250+
#[default]
250251
None,
251252
/// T2CL Template.
252253
T2CL,
@@ -274,12 +275,6 @@ impl fmt::Display for CpuFeaturesTemplate {
274275
}
275276
}
276277

277-
impl Default for CpuFeaturesTemplate {
278-
fn default() -> Self {
279-
CpuFeaturesTemplate::None
280-
}
281-
}
282-
283278
#[cfg(test)]
284279
mod tests {
285280
use super::*;

src/vmm/src/vmm_config/snapshot.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,15 @@ use serde::{Deserialize, Serialize};
99

1010
/// The snapshot type options that are available when
1111
/// creating a new snapshot.
12-
#[derive(Debug, PartialEq, Eq, Deserialize, Serialize)]
12+
#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
1313
pub enum SnapshotType {
1414
/// Diff snapshot.
1515
Diff,
1616
/// Full snapshot.
17+
#[default]
1718
Full,
1819
}
1920

20-
impl Default for SnapshotType {
21-
fn default() -> Self {
22-
SnapshotType::Full
23-
}
24-
}
25-
2621
/// Specifies the method through which guest memory will get populated when
2722
/// resuming from a snapshot:
2823
/// 1) A file that contains the guest memory to be loaded,

0 commit comments

Comments
 (0)