From 3b8d1f141114a5b20d6e38ae2033db4f0c9b2828 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 25 Mar 2021 17:01:21 +0000 Subject: [PATCH] vmm: Address Rust 1.51.0 clippy issue (vec_init_then_push) warning: calls to `push` immediately after creation --> vmm/src/cpu.rs:630:9 | 630 | / let mut cpuid_patches = Vec::new(); 631 | | 632 | | // Patch tsc deadline timer bit 633 | | cpuid_patches.push(CpuidPatch { ... | 662 | | edx_bit: Some(MTRR_EDX_BIT), 663 | | }); | |___________^ help: consider using the `vec![]` macro: `let mut cpuid_patches = vec![..];` | = note: `#[warn(clippy::vec_init_then_push)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push Signed-off-by: Rob Bradford --- vmm/src/cpu.rs | 66 +++++++++++++++++++-------------------- vmm/src/device_manager.rs | 7 ++--- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index bb04276e6..ad42b8340 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -627,40 +627,38 @@ impl CpuManager { phys_bits: u8, kvm_hyperv: bool, ) -> Result { - let mut cpuid_patches = Vec::new(); - - // Patch tsc deadline timer bit - cpuid_patches.push(CpuidPatch { - function: 1, - index: 0, - flags_bit: None, - eax_bit: None, - ebx_bit: None, - ecx_bit: Some(TSC_DEADLINE_TIMER_ECX_BIT), - edx_bit: None, - }); - - // Patch hypervisor bit - cpuid_patches.push(CpuidPatch { - function: 1, - index: 0, - flags_bit: None, - eax_bit: None, - ebx_bit: None, - ecx_bit: Some(HYPERVISOR_ECX_BIT), - edx_bit: None, - }); - - // Enable MTRR feature - cpuid_patches.push(CpuidPatch { - function: 1, - index: 0, - flags_bit: None, - eax_bit: None, - ebx_bit: None, - ecx_bit: None, - edx_bit: Some(MTRR_EDX_BIT), - }); + let cpuid_patches = vec![ + // Patch tsc deadline timer bit + CpuidPatch { + function: 1, + index: 0, + flags_bit: None, + eax_bit: None, + ebx_bit: None, + ecx_bit: Some(TSC_DEADLINE_TIMER_ECX_BIT), + edx_bit: None, + }, + // Patch hypervisor bit + CpuidPatch { + function: 1, + index: 0, + flags_bit: None, + eax_bit: None, + ebx_bit: None, + ecx_bit: Some(HYPERVISOR_ECX_BIT), + edx_bit: None, + }, + // Enable MTRR feature + CpuidPatch { + function: 1, + index: 0, + flags_bit: None, + eax_bit: None, + ebx_bit: None, + ecx_bit: None, + edx_bit: Some(MTRR_EDX_BIT), + }, + ]; // Supported CPUID let mut cpuid = hypervisor diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 9724ffa8c..6b83af6c2 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -2304,11 +2304,10 @@ impl DeviceManager { ) .map_err(DeviceManagerError::MemoryManager)?; - let mut region_list = Vec::new(); - region_list.push(VirtioSharedMemory { + let region_list = vec![VirtioSharedMemory { offset: 0, len: cache_size, - }); + }]; Some(( VirtioSharedMemoryList { @@ -4000,7 +3999,7 @@ impl BusDevice for DeviceManager { B0EJ_FIELD_OFFSET => { assert!(data.len() == B0EJ_FIELD_SIZE); let mut data_array: [u8; 4] = [0, 0, 0, 0]; - data_array.copy_from_slice(&data[..]); + data_array.copy_from_slice(&data); let device_bitmap = u32::from_le_bytes(data_array); for device_id in 0..32 {