Skip to content

Commit ae0c754

Browse files
committed
Fix clippy warnings
Signed-off-by: Matej Hrica <[email protected]>
1 parent adb5eb1 commit ae0c754

File tree

7 files changed

+44
-60
lines changed

7 files changed

+44
-60
lines changed

src/arch/src/x86_64/regs.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ mod tests {
213213
}
214214

215215
fn read_u64(gm: &GuestMemoryMmap, offset: u64) -> u64 {
216-
let read_addr = GuestAddress(offset as u64);
216+
let read_addr = GuestAddress(offset);
217217
gm.read_obj(read_addr).unwrap()
218218
}
219219

@@ -253,7 +253,7 @@ mod tests {
253253
assert_eq!((i << 21) + 0x83u64, read_u64(gm, PDE_START + (i * 8)));
254254
}
255255

256-
assert_eq!(PML4_START as u64, sregs.cr3);
256+
assert_eq!({ PML4_START }, sregs.cr3);
257257
assert!(sregs.cr4 & X86_CR4_PAE != 0);
258258
assert!(sregs.cr0 & X86_CR0_PG != 0);
259259
}
@@ -298,9 +298,9 @@ mod tests {
298298
let expected_regs: kvm_regs = kvm_regs {
299299
rflags: 0x0000_0000_0000_0002u64,
300300
rip: 1,
301-
rsp: super::super::layout::BOOT_STACK_POINTER as u64,
302-
rbp: super::super::layout::BOOT_STACK_POINTER as u64,
303-
rsi: super::super::layout::ZERO_PAGE_START as u64,
301+
rsp: super::super::layout::BOOT_STACK_POINTER,
302+
rbp: super::super::layout::BOOT_STACK_POINTER,
303+
rsi: super::super::layout::ZERO_PAGE_START,
304304
..Default::default()
305305
};
306306

src/cpuid/src/cpu_leaf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub mod leaf_0x4 {
8484
use crate::bit_helper::BitRange;
8585

8686
// inherit eax from leaf_cache_parameters
87-
pub use crate::cpu_leaf::leaf_cache_parameters::eax::*;
87+
8888

8989
pub const MAX_CORES_PER_PACKAGE_BITRANGE: BitRange = bit_range!(31, 26);
9090
}
@@ -300,7 +300,7 @@ pub mod leaf_0x8000001d {
300300
pub const LEAF_NUM: u32 = 0x8000_001d;
301301

302302
// inherit eax from leaf_cache_parameters
303-
pub use crate::cpu_leaf::leaf_cache_parameters::eax;
303+
304304
}
305305

306306
// Extended APIC ID Leaf

src/devices/src/legacy/serial.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -524,13 +524,13 @@ mod tests {
524524
fn test_serial_dlab() {
525525
let mut serial = Serial::new_sink(EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap());
526526

527-
serial.write(0, u64::from(LCR), &[LCR_DLAB_BIT as u8]);
527+
serial.write(0, u64::from(LCR), &[LCR_DLAB_BIT]);
528528
serial.write(0, u64::from(DLAB_LOW), &[0x12_u8]);
529529
serial.write(0, u64::from(DLAB_HIGH), &[0x34_u8]);
530530

531531
let mut data = [0u8];
532532
serial.read(0, u64::from(LCR), &mut data[..]);
533-
assert_eq!(data[0], LCR_DLAB_BIT as u8);
533+
assert_eq!(data[0], { LCR_DLAB_BIT });
534534
serial.read(0, u64::from(DLAB_LOW), &mut data[..]);
535535
assert_eq!(data[0], 0x12);
536536
serial.read(0, u64::from(DLAB_HIGH), &mut data[..]);
@@ -541,16 +541,16 @@ mod tests {
541541
fn test_serial_modem() {
542542
let mut serial = Serial::new_sink(EventFd::new(utils::eventfd::EFD_NONBLOCK).unwrap());
543543

544-
serial.write(0, u64::from(MCR), &[MCR_LOOP_BIT as u8]);
544+
serial.write(0, u64::from(MCR), &[MCR_LOOP_BIT]);
545545
serial.write(0, u64::from(DATA), &[b'a']);
546546
serial.write(0, u64::from(DATA), &[b'b']);
547547
serial.write(0, u64::from(DATA), &[b'c']);
548548

549549
let mut data = [0u8];
550550
serial.read(0, u64::from(MSR), &mut data[..]);
551-
assert_eq!(data[0], DEFAULT_MODEM_STATUS as u8);
551+
assert_eq!(data[0], { DEFAULT_MODEM_STATUS });
552552
serial.read(0, u64::from(MCR), &mut data[..]);
553-
assert_eq!(data[0], MCR_LOOP_BIT as u8);
553+
assert_eq!(data[0], { MCR_LOOP_BIT });
554554
serial.read(0, u64::from(DATA), &mut data[..]);
555555
assert_eq!(data[0], b'a');
556556
serial.read(0, u64::from(DATA), &mut data[..]);

src/devices/src/virtio/fs/descriptor_utils.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ mod tests {
545545
use DescriptorType::*;
546546

547547
let memory_start_addr = GuestAddress(0x0);
548-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
548+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
549549

550550
let chain = create_descriptor_chain(
551551
&memory,
@@ -564,7 +564,7 @@ mod tests {
564564
assert_eq!(reader.available_bytes(), 106);
565565
assert_eq!(reader.bytes_read(), 0);
566566

567-
let mut buffer = [0 as u8; 64];
567+
let mut buffer = [0_u8; 64];
568568
if let Err(_) = reader.read_exact(&mut buffer) {
569569
panic!("read_exact should not fail here");
570570
}
@@ -586,7 +586,7 @@ mod tests {
586586
use DescriptorType::*;
587587

588588
let memory_start_addr = GuestAddress(0x0);
589-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
589+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
590590

591591
let chain = create_descriptor_chain(
592592
&memory,
@@ -605,7 +605,7 @@ mod tests {
605605
assert_eq!(writer.available_bytes(), 106);
606606
assert_eq!(writer.bytes_written(), 0);
607607

608-
let mut buffer = [0 as u8; 64];
608+
let mut buffer = [0_u8; 64];
609609
if let Err(_) = writer.write_all(&mut buffer) {
610610
panic!("write_all should not fail here");
611611
}
@@ -627,7 +627,7 @@ mod tests {
627627
use DescriptorType::*;
628628

629629
let memory_start_addr = GuestAddress(0x0);
630-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
630+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
631631

632632
let chain = create_descriptor_chain(
633633
&memory,
@@ -652,7 +652,7 @@ mod tests {
652652
use DescriptorType::*;
653653

654654
let memory_start_addr = GuestAddress(0x0);
655-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
655+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
656656

657657
let chain = create_descriptor_chain(
658658
&memory,
@@ -677,7 +677,7 @@ mod tests {
677677
use DescriptorType::*;
678678

679679
let memory_start_addr = GuestAddress(0x0);
680-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
680+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
681681

682682
let chain = create_descriptor_chain(
683683
&memory,
@@ -725,7 +725,7 @@ mod tests {
725725
use DescriptorType::*;
726726

727727
let memory_start_addr = GuestAddress(0x0);
728-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
728+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
729729

730730
let secret: Le32 = 0x12345678.into();
731731

@@ -764,7 +764,7 @@ mod tests {
764764
use DescriptorType::*;
765765

766766
let memory_start_addr = GuestAddress(0x0);
767-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
767+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
768768

769769
let chain = create_descriptor_chain(
770770
&memory,
@@ -794,7 +794,7 @@ mod tests {
794794
use DescriptorType::*;
795795

796796
let memory_start_addr = GuestAddress(0x0);
797-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
797+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
798798

799799
let chain = create_descriptor_chain(
800800
&memory,
@@ -823,7 +823,7 @@ mod tests {
823823
use DescriptorType::*;
824824

825825
let memory_start_addr = GuestAddress(0x0);
826-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
826+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
827827

828828
let chain = create_descriptor_chain(
829829
&memory,
@@ -852,7 +852,7 @@ mod tests {
852852
use DescriptorType::*;
853853

854854
let memory_start_addr = GuestAddress(0x0);
855-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
855+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
856856

857857
let chain = create_descriptor_chain(
858858
&memory,
@@ -881,7 +881,7 @@ mod tests {
881881
use DescriptorType::*;
882882

883883
let memory_start_addr = GuestAddress(0x0);
884-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
884+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
885885

886886
let chain = create_descriptor_chain(
887887
&memory,
@@ -910,7 +910,7 @@ mod tests {
910910
use DescriptorType::*;
911911

912912
let memory_start_addr = GuestAddress(0x0);
913-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
913+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
914914

915915
let chain = create_descriptor_chain(
916916
&memory,
@@ -939,7 +939,7 @@ mod tests {
939939
use DescriptorType::*;
940940

941941
let memory_start_addr = GuestAddress(0x0);
942-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
942+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
943943

944944
let chain = create_descriptor_chain(
945945
&memory,
@@ -951,7 +951,7 @@ mod tests {
951951
.expect("create_descriptor_chain failed");
952952
let mut reader = Reader::new(&memory, chain).expect("failed to create Reader");
953953

954-
let mut buf = vec![0u8; 64];
954+
let mut buf = [0u8; 64];
955955
assert_eq!(
956956
reader.read(&mut buf[..]).expect("failed to read to buffer"),
957957
48
@@ -963,7 +963,7 @@ mod tests {
963963
use DescriptorType::*;
964964

965965
let memory_start_addr = GuestAddress(0x0);
966-
let memory = GuestMemoryMmap::from_ranges(&vec![(memory_start_addr, 0x10000)]).unwrap();
966+
let memory = GuestMemoryMmap::from_ranges(&[(memory_start_addr, 0x10000)]).unwrap();
967967

968968
let chain = create_descriptor_chain(
969969
&memory,
@@ -975,7 +975,7 @@ mod tests {
975975
.expect("create_descriptor_chain failed");
976976
let mut writer = Writer::new(&memory, chain).expect("failed to create Writer");
977977

978-
let buf = vec![0xdeu8; 64];
978+
let buf = [0xdeu8; 64];
979979
assert_eq!(
980980
writer.write(&buf[..]).expect("failed to write from buffer"),
981981
48

src/devices/src/virtio/fs/filesystem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub use super::fuse::FsOptions;
1616
pub use fuse::OpenOptions;
1717
pub use fuse::RemovemappingOne;
1818
pub use fuse::SetattrValid;
19-
pub use fuse::ROOT_ID;
19+
2020

2121
/// Information about a path in the filesystem.
2222
pub struct Entry {

src/devices/src/virtio/mmio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ pub(crate) mod tests {
470470
}
471471

472472
fn set_device_status(d: &mut MmioTransport, status: u32) {
473-
let mut buf = vec![0; 4];
473+
let mut buf = [0; 4];
474474
write_le_u32(&mut buf[..], status);
475475
d.write(0, 0x70, &buf[..]);
476476
}
@@ -778,7 +778,7 @@ pub(crate) mod tests {
778778
device_status::ACKNOWLEDGE | device_status::DRIVER | device_status::FEATURES_OK
779779
);
780780

781-
let mut buf = vec![0; 4];
781+
let mut buf = [0; 4];
782782
let queue_len = d.locked_device().queues().len();
783783
for q in 0..queue_len {
784784
d.queue_select = q as u32;
@@ -831,7 +831,7 @@ pub(crate) mod tests {
831831
);
832832

833833
// Setup queue data structures
834-
let mut buf = vec![0; 4];
834+
let mut buf = [0; 4];
835835
let queues_count = d.locked_device().queues().len();
836836
for q in 0..queues_count {
837837
d.queue_select = q as u32;
@@ -865,7 +865,7 @@ pub(crate) mod tests {
865865
fn test_bus_device_reset() {
866866
let m = GuestMemoryMmap::from_ranges(&[(GuestAddress(0), 0x1000)]).unwrap();
867867
let mut d = MmioTransport::new(m, Arc::new(Mutex::new(DummyDevice::new())));
868-
let mut buf = vec![0; 4];
868+
let mut buf = [0; 4];
869869

870870
assert!(!d.are_queues_valid());
871871
assert!(!d.locked_device().is_activated());

src/utils/src/linux/epoll.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,20 @@ mod tests {
267267
// For EPOLL_CTL_ADD behavior we will try to add some fds with different event masks into
268268
// the interest list of epoll instance.
269269
assert!(epoll
270-
.ctl(
271-
ControlOperation::Add,
272-
event_fd_1.as_raw_fd() as i32,
273-
&event_1
274-
)
270+
.ctl(ControlOperation::Add, event_fd_1.as_raw_fd(), &event_1)
275271
.is_ok());
276272

277273
// We can't add twice the same fd to epoll interest list.
278274
assert!(epoll
279-
.ctl(
280-
ControlOperation::Add,
281-
event_fd_1.as_raw_fd() as i32,
282-
&event_1
283-
)
275+
.ctl(ControlOperation::Add, event_fd_1.as_raw_fd(), &event_1)
284276
.is_err());
285277

286278
let event_fd_2 = EventFd::new(libc::EFD_NONBLOCK).unwrap();
287279
event_fd_2.write(1).unwrap();
288280
assert!(epoll
289281
.ctl(
290282
ControlOperation::Add,
291-
event_fd_2.as_raw_fd() as i32,
283+
event_fd_2.as_raw_fd(),
292284
// For this fd, we want an Event instance that has `data` field set to other
293285
// value than the value of the fd and `events` without EPOLLIN type set.
294286
&EpollEvent::new(EventSet::OUT, 10)
@@ -301,11 +293,7 @@ mod tests {
301293
let event_fd_3 = EventFd::new(libc::EFD_NONBLOCK).unwrap();
302294
let event_3 = EpollEvent::new(EventSet::OUT | EventSet::IN, event_fd_3.as_raw_fd() as u64);
303295
assert!(epoll
304-
.ctl(
305-
ControlOperation::Add,
306-
event_fd_3.as_raw_fd() as i32,
307-
&event_3
308-
)
296+
.ctl(ControlOperation::Add, event_fd_3.as_raw_fd(), &event_3)
309297
.is_ok());
310298

311299
// Let's check `epoll_wait()` behavior for our epoll instance.
@@ -341,19 +329,15 @@ mod tests {
341329
// that we want to monitor this time on event_fd_1.
342330
event_1 = EpollEvent::new(EventSet::OUT, 20);
343331
assert!(epoll
344-
.ctl(
345-
ControlOperation::Modify,
346-
event_fd_1.as_raw_fd() as i32,
347-
&event_1
348-
)
332+
.ctl(ControlOperation::Modify, event_fd_1.as_raw_fd(), &event_1)
349333
.is_ok());
350334

351335
let event_fd_4 = EventFd::new(libc::EFD_NONBLOCK).unwrap();
352336
// Can't modify a fd that wasn't added to epoll interest list.
353337
assert!(epoll
354338
.ctl(
355339
ControlOperation::Modify,
356-
event_fd_4.as_raw_fd() as i32,
340+
event_fd_4.as_raw_fd(),
357341
&EpollEvent::default()
358342
)
359343
.is_err());
@@ -371,7 +355,7 @@ mod tests {
371355
assert!(epoll
372356
.ctl(
373357
ControlOperation::Modify,
374-
event_fd_1.as_raw_fd() as i32,
358+
event_fd_1.as_raw_fd(),
375359
&EpollEvent::default()
376360
)
377361
.is_ok());
@@ -386,7 +370,7 @@ mod tests {
386370
assert!(epoll
387371
.ctl(
388372
ControlOperation::Delete,
389-
event_fd_2.as_raw_fd() as i32,
373+
event_fd_2.as_raw_fd(),
390374
&EpollEvent::default()
391375
)
392376
.is_ok());
@@ -404,7 +388,7 @@ mod tests {
404388
assert!(epoll
405389
.ctl(
406390
ControlOperation::Delete,
407-
event_fd_4.as_raw_fd() as i32,
391+
event_fd_4.as_raw_fd(),
408392
&EpollEvent::default()
409393
)
410394
.is_err());

0 commit comments

Comments
 (0)