From 05cdef17f469129364da25c705e952f75b333ccf Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Sat, 2 Jan 2021 20:37:05 +0000 Subject: [PATCH] virtio-devices: mem, balloon: Use struct initialisation error: field assignment outside of initializer for an instance created with Default::default() --> virtio-devices/src/mem.rs:496:9 | 496 | resp.resp_type = resp_type; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: consider initializing the variable with `mem::VirtioMemResp { resp_type: resp_type, ..Default::default() }` and removing relevant reassignments --> virtio-devices/src/mem.rs:495:9 | 495 | let mut resp = VirtioMemResp::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default Signed-off-by: Rob Bradford --- virtio-devices/src/balloon.rs | 6 ++++-- virtio-devices/src/mem.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/virtio-devices/src/balloon.rs b/virtio-devices/src/balloon.rs index 640ef7f21..89bea794e 100644 --- a/virtio-devices/src/balloon.rs +++ b/virtio-devices/src/balloon.rs @@ -321,8 +321,10 @@ impl Balloon { pub fn new(id: String, size: u64, seccomp_action: SeccompAction) -> io::Result { let avail_features = 1u64 << VIRTIO_F_VERSION_1; - let mut config = VirtioBalloonConfig::default(); - config.num_pages = (size >> VIRTIO_BALLOON_PFN_SHIFT) as u32; + let config = VirtioBalloonConfig { + num_pages: (size >> VIRTIO_BALLOON_PFN_SHIFT) as u32, + ..Default::default() + }; Ok(Balloon { common: VirtioCommon { diff --git a/virtio-devices/src/mem.rs b/virtio-devices/src/mem.rs index 0ec41ffa6..045242a63 100644 --- a/virtio-devices/src/mem.rs +++ b/virtio-devices/src/mem.rs @@ -489,12 +489,14 @@ impl MemEpollHandler { fn virtio_mem_send_response( mem: &GuestMemoryMmap, resp_type: u16, - resp_state: u16, + state: u16, status_addr: GuestAddress, ) -> u32 { - let mut resp = VirtioMemResp::default(); - resp.resp_type = resp_type; - resp.state.state = resp_state; + let resp = VirtioMemResp { + resp_type, + state: VirtioMemRespState { state }, + ..Default::default() + }; match mem.write_obj(resp, status_addr) { Ok(_) => size_of::() as u32, Err(e) => {