misc: clippy: add map_unwrap_or
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
parent
dda89d7027
commit
d2b19bb969
8 changed files with 22 additions and 26 deletions
|
|
@ -172,6 +172,7 @@ suspicious = "deny"
|
|||
# Individual Lints
|
||||
assertions_on_result_states = "deny"
|
||||
manual_string_new = "deny"
|
||||
map_unwrap_or = "deny"
|
||||
semicolon_if_nothing_returned = "deny"
|
||||
undocumented_unsafe_blocks = "deny"
|
||||
uninlined_format_args = "deny"
|
||||
|
|
|
|||
|
|
@ -648,8 +648,10 @@ impl PvmemcontrolBusDevice {
|
|||
.find_connection(conn)
|
||||
.ok_or(Error::InvalidConnection(conn.command))
|
||||
})
|
||||
.map(|gpa| self.handle_pvmemcontrol_request(gpa))
|
||||
.unwrap_or_else(|err| warn!("{err:?}"));
|
||||
.map_or_else(
|
||||
|err| warn!("{err:?}"),
|
||||
|gpa| self.handle_pvmemcontrol_request(gpa),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1161,7 +1161,7 @@ fn main() {
|
|||
if let Some(api_client::Error::ServerResponse(status_code, body)) =
|
||||
error.downcast_ref::<api_client::Error>()
|
||||
{
|
||||
let body = body.as_ref().map(|body| body.as_str()).unwrap_or("");
|
||||
let body = body.as_ref().map_or("", |body| body.as_str());
|
||||
|
||||
// Retrieve the list of error messages back.
|
||||
let lines: Vec<&str> = match serde_json::from_str(body) {
|
||||
|
|
|
|||
|
|
@ -735,9 +735,7 @@ impl Block {
|
|||
(disk_nsectors, avail_features, 0, config, false)
|
||||
};
|
||||
|
||||
let serial = serial
|
||||
.map(Vec::from)
|
||||
.unwrap_or_else(|| build_serial(&disk_path));
|
||||
let serial = serial.map_or_else(|| build_serial(&disk_path), Vec::from);
|
||||
|
||||
Ok(Block {
|
||||
common: VirtioCommon {
|
||||
|
|
@ -773,21 +771,20 @@ impl Block {
|
|||
// TODO In future, we could add a `lock_granularity=` configuration to the CLI.
|
||||
// For now, we stick to QEMU behavior.
|
||||
fn lock_granularity(&mut self) -> LockGranularity {
|
||||
let fallback = LockGranularity::WholeFile;
|
||||
|
||||
self.disk_image
|
||||
.size()
|
||||
.map(|size| LockGranularity::ByteRange(0, size))
|
||||
self.disk_image.size().map_or_else(
|
||||
// use a safe fallback
|
||||
.unwrap_or_else(|e| {
|
||||
log::warn!(
|
||||
|e| {
|
||||
let fallback = LockGranularity::WholeFile;
|
||||
warn!(
|
||||
"Can't get disk size for id={},path={}, falling back to {:?}: error: {e}",
|
||||
self.id,
|
||||
self.disk_path.display(),
|
||||
fallback
|
||||
);
|
||||
fallback
|
||||
})
|
||||
},
|
||||
|size| LockGranularity::ByteRange(0, size),
|
||||
)
|
||||
}
|
||||
|
||||
/// Tries to set an advisory lock for the corresponding disk image.
|
||||
|
|
|
|||
|
|
@ -1562,8 +1562,7 @@ impl BalloonConfig {
|
|||
let size = parser
|
||||
.convert::<ByteSized>("size")
|
||||
.map_err(Error::ParseBalloon)?
|
||||
.map(|v| v.0)
|
||||
.unwrap_or(0);
|
||||
.map_or(0, |v| v.0);
|
||||
|
||||
let deflate_on_oom = parser
|
||||
.convert::<Toggle>("deflate_on_oom")
|
||||
|
|
@ -2482,7 +2481,7 @@ impl VmConfig {
|
|||
|
||||
#[cfg(feature = "tdx")]
|
||||
{
|
||||
let tdx_enabled = self.platform.as_ref().map(|p| p.tdx).unwrap_or(false);
|
||||
let tdx_enabled = self.platform.as_ref().is_some_and(|p| p.tdx);
|
||||
// At this point we know payload isn't None.
|
||||
if tdx_enabled && self.payload.as_ref().unwrap().firmware.is_none() {
|
||||
return Err(ValidationError::TdxFirmwareMissing);
|
||||
|
|
@ -3110,12 +3109,12 @@ impl VmConfig {
|
|||
|
||||
#[cfg(feature = "tdx")]
|
||||
pub fn is_tdx_enabled(&self) -> bool {
|
||||
self.platform.as_ref().map(|p| p.tdx).unwrap_or(false)
|
||||
self.platform.as_ref().is_some_and(|p| p.tdx)
|
||||
}
|
||||
|
||||
#[cfg(feature = "sev_snp")]
|
||||
pub fn is_sev_snp_enabled(&self) -> bool {
|
||||
self.platform.as_ref().map(|p| p.sev_snp).unwrap_or(false)
|
||||
self.platform.as_ref().is_some_and(|p| p.sev_snp)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2113,8 +2113,7 @@ impl DeviceManager {
|
|||
.debug_console
|
||||
.clone()
|
||||
.iobase
|
||||
.map(|port| port as u64)
|
||||
.unwrap_or(debug_console::DEFAULT_PORT);
|
||||
.map_or(debug_console::DEFAULT_PORT, |port| port as u64);
|
||||
|
||||
self.bus_devices
|
||||
.push(Arc::clone(&debug_console) as Arc<dyn BusDeviceSync>);
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ unsafe fn close_unused_fds(keep_fds: &mut [RawFd]) {
|
|||
// The next fd is the one at i, because the indexes in the
|
||||
// iterator are offset by one due to the initial 0.
|
||||
let next_keep_fd = keep_fds.get(i);
|
||||
let last = next_keep_fd.map(|fd| fd - 1).unwrap_or(RawFd::MAX);
|
||||
let last = next_keep_fd.map_or(RawFd::MAX, |fd| fd - 1);
|
||||
|
||||
if first > last {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -763,8 +763,7 @@ impl Vm {
|
|||
.unwrap()
|
||||
.payload
|
||||
.as_ref()
|
||||
.map(|p| p.fw_cfg_config.is_some())
|
||||
.unwrap_or(false);
|
||||
.is_some_and(|p| p.fw_cfg_config.is_some());
|
||||
if fw_cfg_config {
|
||||
device_manager
|
||||
.lock()
|
||||
|
|
@ -2338,8 +2337,7 @@ impl Vm {
|
|||
.unwrap()
|
||||
.payload
|
||||
.as_ref()
|
||||
.map(|p| p.fw_cfg_config.is_some())
|
||||
.unwrap_or(false);
|
||||
.is_some_and(|p| p.fw_cfg_config.is_some());
|
||||
if fw_cfg_enabled {
|
||||
let fw_cfg_config = self
|
||||
.config
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue