Skip to content

Commit 61e57e1

Browse files
RuoqingHerbradford
authored andcommitted
misc: Further improve imports styling
By introducing `imports_granularity="Module"` format strategy, effectively groups imports from the same module into one line or block, improving maintainability and readability. Signed-off-by: Ruoqing He <[email protected]>
1 parent 9013d8b commit 61e57e1

Some content is hidden

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

99 files changed

+360
-515
lines changed

.rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
edition = "2021"
22
group_imports="StdExternalCrate"
3+
imports_granularity="Module"
4+

arch/src/aarch64/fdt.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66
// Use of this source code is governed by a BSD-style license that can be
77
// found in the THIRD-PARTY file.
88

9-
use std::cmp;
109
use std::collections::HashMap;
1110
use std::ffi::CStr;
1211
use std::fmt::Debug;
13-
use std::fs;
1412
use std::path::Path;
15-
use std::result;
16-
use std::str;
1713
use std::sync::{Arc, Mutex};
14+
use std::{cmp, fs, result, str};
1815

1916
use byteorder::{BigEndian, ByteOrder};
2017
use hypervisor::arch::aarch64::gic::Vgic;
2118
use thiserror::Error;
2219
use vm_fdt::{FdtWriter, FdtWriterResult};
2320
use vm_memory::{Address, Bytes, GuestMemory, GuestMemoryError, GuestMemoryRegion};
2421

25-
use super::super::DeviceType;
26-
use super::super::GuestMemoryMmap;
27-
use super::super::InitramfsConfig;
22+
use super::super::{DeviceType, GuestMemoryMmap, InitramfsConfig};
2823
use super::layout::{
2924
IRQ_BASE, MEM_32BIT_DEVICES_SIZE, MEM_32BIT_DEVICES_START, MEM_PCI_IO_SIZE, MEM_PCI_IO_START,
3025
PCI_HIGH_BASE, PCI_MMIO_CONFIG_SIZE_PER_SEGMENT,

arch/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
extern crate log;
1212

1313
use std::collections::BTreeMap;
14-
use std::fmt;
15-
use std::result;
1614
use std::sync::Arc;
15+
use std::{fmt, result};
1716

1817
use serde::{Deserialize, Serialize};
1918
use thiserror::Error;

arch/src/x86_64/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ use vm_memory::{
2727
GuestMemoryRegion, GuestUsize,
2828
};
2929

30-
use crate::GuestMemoryMmap;
31-
use crate::InitramfsConfig;
32-
use crate::RegionType;
30+
use crate::{GuestMemoryMmap, InitramfsConfig, RegionType};
3331
mod smbios;
3432
use std::arch::x86_64;
3533
#[cfg(feature = "tdx")]

arch/src/x86_64/mptable.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the LICENSE-BSD-3-Clause file.
77

8-
use std::mem;
9-
use std::result;
10-
use std::slice;
8+
use std::{mem, result, slice};
119

1210
use libc::c_uchar;
1311
use thiserror::Error;
@@ -306,9 +304,8 @@ pub fn setup_mptable(
306304

307305
#[cfg(test)]
308306
mod tests {
309-
use vm_memory::{
310-
bitmap::BitmapSlice, GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile,
311-
};
307+
use vm_memory::bitmap::BitmapSlice;
308+
use vm_memory::{GuestUsize, VolatileMemoryError, VolatileSlice, WriteVolatile};
312309

313310
use super::*;
314311
use crate::layout::MPTABLE_START;

arch/src/x86_64/smbios.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
//
77
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
88

9-
use std::mem;
10-
use std::result;
11-
use std::slice;
9+
use std::{mem, result, slice};
1210

1311
use thiserror::Error;
1412
use uuid::Uuid;
15-
use vm_memory::ByteValued;
16-
use vm_memory::{Address, Bytes, GuestAddress};
13+
use vm_memory::{Address, ByteValued, Bytes, GuestAddress};
1714

1815
use crate::layout::SMBIOS_START;
1916
use crate::GuestMemoryMmap;

block/src/lib.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,16 @@ pub mod vhdx;
3131
pub mod vhdx_sync;
3232

3333
use std::alloc::{alloc_zeroed, dealloc, Layout};
34-
use std::cmp;
3534
use std::collections::VecDeque;
3635
use std::fmt::Debug;
3736
use std::fs::File;
3837
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
3938
use std::os::linux::fs::MetadataExt;
4039
use std::os::unix::io::AsRawFd;
4140
use std::path::Path;
42-
use std::result;
43-
use std::sync::Arc;
44-
use std::sync::MutexGuard;
41+
use std::sync::{Arc, MutexGuard};
4542
use std::time::Instant;
43+
use std::{cmp, result};
4644

4745
#[cfg(feature = "io_uring")]
4846
use io_uring::{opcode, IoUring, Probe};
@@ -52,14 +50,13 @@ use smallvec::SmallVec;
5250
use thiserror::Error;
5351
use virtio_bindings::virtio_blk::*;
5452
use virtio_queue::DescriptorChain;
53+
use vm_memory::bitmap::Bitmap;
5554
use vm_memory::{
56-
bitmap::Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError,
57-
GuestMemoryLoadGuard,
55+
ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryLoadGuard,
5856
};
5957
use vm_virtio::{AccessPlatform, Translatable};
60-
use vmm_sys_util::aio;
6158
use vmm_sys_util::eventfd::EventFd;
62-
use vmm_sys_util::{ioctl_io_nr, ioctl_ioc_nr};
59+
use vmm_sys_util::{aio, ioctl_io_nr, ioctl_ioc_nr};
6360

6461
use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult};
6562
use crate::fixed_vhd::FixedVhd;

block/src/qcow/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
1919
use libc::{EINVAL, ENOSPC, ENOTSUP};
2020
use remain::sorted;
2121
use thiserror::Error;
22-
use vmm_sys_util::{
23-
file_traits::FileSetLen, file_traits::FileSync, seek_hole::SeekHole, write_zeroes::PunchHole,
24-
write_zeroes::WriteZeroesAt,
25-
};
22+
use vmm_sys_util::file_traits::{FileSetLen, FileSync};
23+
use vmm_sys_util::seek_hole::SeekHole;
24+
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
2625

26+
use crate::qcow::qcow_raw_file::QcowRawFile;
2727
pub use crate::qcow::raw_file::RawFile;
28-
use crate::qcow::{
29-
qcow_raw_file::QcowRawFile,
30-
refcount::RefCount,
31-
vec_cache::{CacheMap, Cacheable, VecCache},
32-
};
28+
use crate::qcow::refcount::RefCount;
29+
use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache};
3330
use crate::BlockBackend;
3431

3532
/// Nesting depth limit for disk formats that can open other disk files.

block/src/qcow/raw_file.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use std::os::unix::io::{AsRawFd, RawFd};
1515
use std::slice;
1616

1717
use libc::c_void;
18-
use vmm_sys_util::{seek_hole::SeekHole, write_zeroes::PunchHole, write_zeroes::WriteZeroesAt};
18+
use vmm_sys_util::seek_hole::SeekHole;
19+
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
1920

2021
use crate::BlockBackend;
2122

block/src/qcow/refcount.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use std::io;
99
use libc::EINVAL;
1010
use thiserror::Error;
1111

12-
use crate::qcow::{
13-
qcow_raw_file::QcowRawFile,
14-
vec_cache::{CacheMap, Cacheable, VecCache},
15-
};
12+
use crate::qcow::qcow_raw_file::QcowRawFile;
13+
use crate::qcow::vec_cache::{CacheMap, Cacheable, VecCache};
1614

1715
#[derive(Debug, Error)]
1816
pub enum Error {

block/src/vhdx/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ use remain::sorted;
1111
use thiserror::Error;
1212
use uuid::Uuid;
1313

14-
use crate::vhdx::{
15-
vhdx_bat::{BatEntry, VhdxBatError},
16-
vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError},
17-
vhdx_io::VhdxIoError,
18-
vhdx_metadata::{DiskSpec, VhdxMetadataError},
19-
};
14+
use crate::vhdx::vhdx_bat::{BatEntry, VhdxBatError};
15+
use crate::vhdx::vhdx_header::{RegionInfo, RegionTableEntry, VhdxHeader, VhdxHeaderError};
16+
use crate::vhdx::vhdx_io::VhdxIoError;
17+
use crate::vhdx::vhdx_metadata::{DiskSpec, VhdxMetadataError};
2018
use crate::BlockBackend;
2119

2220
macro_rules! div_round_up {

block/src/vhdx/vhdx_bat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
1010
use remain::sorted;
1111
use thiserror::Error;
1212

13-
use crate::vhdx::{vhdx_header::RegionTableEntry, vhdx_metadata::DiskSpec};
13+
use crate::vhdx::vhdx_header::RegionTableEntry;
14+
use crate::vhdx::vhdx_metadata::DiskSpec;
1415

1516
// Payload BAT Entry States
1617
pub const PAYLOAD_BLOCK_NOT_PRESENT: u64 = 0;

block/src/vhdx/vhdx_io.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use std::io::{self, Read, Seek, SeekFrom, Write};
88
use remain::sorted;
99
use thiserror::Error;
1010

11-
use crate::vhdx::{
12-
vhdx_bat::{self, BatEntry, VhdxBatError},
13-
vhdx_metadata::{self, DiskSpec},
14-
};
11+
use crate::vhdx::vhdx_bat::{self, BatEntry, VhdxBatError};
12+
use crate::vhdx::vhdx_metadata::{self, DiskSpec};
1513

1614
const SECTOR_SIZE: u64 = 512;
1715

devices/src/gic.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use std::sync::{Arc, Mutex};
99

1010
use anyhow::anyhow;
1111
use arch::layout;
12-
use hypervisor::{
13-
arch::aarch64::gic::{Vgic, VgicConfig},
14-
CpuState, GicState,
15-
};
12+
use hypervisor::arch::aarch64::gic::{Vgic, VgicConfig};
13+
use hypervisor::{CpuState, GicState};
1614
use vm_device::interrupt::{
1715
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
1816
LegacyIrqSourceConfig, MsiIrqGroupConfig,

devices/src/interrupt_controller.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
44

5-
use std::io;
6-
use std::result;
5+
use std::{io, result};
76

87
use thiserror::Error;
98
use vmm_sys_util::eventfd::EventFd;

devices/src/legacy/cmos.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
66

77
use std::cmp::min;
8-
use std::mem;
98
use std::sync::atomic::{AtomicBool, Ordering};
109
use std::sync::{Arc, Barrier};
11-
use std::thread;
10+
use std::{mem, thread};
1211

1312
// https://github.com/rust-lang/libc/issues/1848
1413
#[cfg_attr(target_env = "musl", allow(deprecated))]

devices/src/legacy/gpio_pl061.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
//! This module implements an ARM PrimeCell General Purpose Input/Output(PL061) to support gracefully poweroff microvm from external.
88
//!
99
10-
use std::io;
11-
use std::result;
1210
use std::sync::{Arc, Barrier};
11+
use std::{io, result};
1312

1413
use serde::{Deserialize, Serialize};
1514
use thiserror::Error;

devices/src/legacy/i8042.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
//
55
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
66

7-
use std::sync::{
8-
atomic::{AtomicBool, Ordering},
9-
Arc, Barrier,
10-
};
7+
use std::sync::atomic::{AtomicBool, Ordering};
8+
use std::sync::{Arc, Barrier};
119
use std::thread;
1210

1311
use vm_device::BusDevice;

devices/src/pvmemcontrol.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6-
use std::{
7-
collections::HashMap,
8-
ffi::CString,
9-
io, result,
10-
sync::{Arc, Barrier, Mutex, RwLock},
11-
};
6+
use std::collections::HashMap;
7+
use std::ffi::CString;
8+
use std::sync::{Arc, Barrier, Mutex, RwLock};
9+
use std::{io, result};
1210

1311
use num_enum::TryFromPrimitive;
1412
use pci::{
1513
BarReprogrammingParams, PciBarConfiguration, PciBarPrefetchable, PciBarRegionType,
1614
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
1715
};
1816
use thiserror::Error;
19-
use vm_allocator::{page_size::get_page_size, AddressAllocator, SystemAllocator};
17+
use vm_allocator::page_size::get_page_size;
18+
use vm_allocator::{AddressAllocator, SystemAllocator};
2019
use vm_device::{BusDeviceSync, Resource};
20+
use vm_memory::bitmap::AtomicBitmap;
2121
use vm_memory::{
22-
bitmap::AtomicBitmap, Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory,
23-
GuestMemoryAtomic, GuestMemoryError, GuestMemoryMmap, Le32, Le64,
22+
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic,
23+
GuestMemoryError, GuestMemoryMmap, Le32, Le64,
2424
};
2525
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
2626

fuzz/fuzz_targets/balloon.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target;
1111
use seccompiler::SeccompAction;
1212
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
1313
use virtio_queue::{Queue, QueueT};
14-
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
14+
use vm_memory::bitmap::AtomicBitmap;
15+
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
1516
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
1617

1718
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

fuzz/fuzz_targets/block.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,20 @@
99
#![no_main]
1010

1111
use std::collections::BTreeMap;
12-
use std::ffi;
1312
use std::fs::File;
14-
use std::io;
1513
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
1614
use std::path::PathBuf;
1715
use std::sync::Arc;
16+
use std::{ffi, io};
1817

19-
use block::{async_io::DiskFile, raw_sync::RawFileDiskSync};
18+
use block::async_io::DiskFile;
19+
use block::raw_sync::RawFileDiskSync;
2020
use libfuzzer_sys::fuzz_target;
2121
use seccompiler::SeccompAction;
2222
use virtio_devices::{Block, VirtioDevice, VirtioInterrupt, VirtioInterruptType};
2323
use virtio_queue::{Queue, QueueT};
24-
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
24+
use vm_memory::bitmap::AtomicBitmap;
25+
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
2526
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
2627

2728
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

fuzz/fuzz_targets/console.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use libfuzzer_sys::fuzz_target;
1313
use seccompiler::SeccompAction;
1414
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
1515
use virtio_queue::{Queue, QueueT};
16-
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
16+
use vm_memory::bitmap::AtomicBitmap;
17+
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
1718
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
1819

1920
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

fuzz/fuzz_targets/http_api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use libfuzzer_sys::fuzz_target;
1212
use micro_http::Request;
1313
use once_cell::sync::Lazy;
1414
use vm_migration::MigratableError;
15+
use vmm::api::http::*;
1516
use vmm::api::{
16-
http::*, ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData,
17-
VmSendMigrationData, VmmPingResponse,
17+
ApiRequest, RequestHandler, VmInfoResponse, VmReceiveMigrationData, VmSendMigrationData,
18+
VmmPingResponse,
1819
};
1920
use vmm::config::RestoreConfig;
2021
use vmm::vm::{Error as VmError, VmState};

fuzz/fuzz_targets/iommu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ use libfuzzer_sys::fuzz_target;
1111
use seccompiler::SeccompAction;
1212
use virtio_devices::{VirtioDevice, VirtioInterrupt, VirtioInterruptType};
1313
use virtio_queue::{Queue, QueueT};
14-
use vm_memory::{bitmap::AtomicBitmap, Bytes, GuestAddress, GuestMemoryAtomic};
14+
use vm_memory::bitmap::AtomicBitmap;
15+
use vm_memory::{Bytes, GuestAddress, GuestMemoryAtomic};
1516
use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK};
1617

1718
type GuestMemoryMmap = vm_memory::GuestMemoryMmap<AtomicBitmap>;

0 commit comments

Comments
 (0)