build: treewide: clippy: collapse nested ifs, use let chains

This bumps the MSRV to 1.88 (also, Rust edition 2024 is mandatory).

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-08-15 09:00:01 +02:00
committed by Bo Chen
parent f73a6c8d8e
commit c995b72384
40 changed files with 574 additions and 608 deletions
+76 -69
View File
@@ -1248,10 +1248,11 @@ impl DiskConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
@@ -1260,13 +1261,13 @@ impl DiskConfig {
}
// Check Block device serial length
if let Some(ref serial) = self.serial {
if serial.len() > VIRTIO_BLK_ID_BYTES as usize {
return Err(ValidationError::InvalidSerialLength(
serial.len(),
VIRTIO_BLK_ID_BYTES as usize,
));
}
if let Some(ref serial) = self.serial
&& serial.len() > VIRTIO_BLK_ID_BYTES as usize
{
return Err(ValidationError::InvalidSerialLength(
serial.len(),
VIRTIO_BLK_ID_BYTES as usize,
));
}
Ok(())
@@ -1496,17 +1497,18 @@ impl NetConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
if let Some(mtu) = self.mtu {
if mtu < virtio_devices::net::MIN_MTU {
return Err(ValidationError::InvalidMtu(mtu));
}
if let Some(mtu) = self.mtu
&& mtu < virtio_devices::net::MIN_MTU
{
return Err(ValidationError::InvalidMtu(mtu));
}
if !self.offload_csum && (self.offload_tso || self.offload_ufo) {
@@ -1633,12 +1635,12 @@ impl FsConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) {
return Err(ValidationError::IommuNotSupportedOnSegment(
self.pci_segment,
));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
{
return Err(ValidationError::IommuNotSupportedOnSegment(
self.pci_segment,
));
}
}
@@ -1795,10 +1797,11 @@ impl PmemConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
@@ -1895,17 +1898,18 @@ impl DebugConsoleConfig {
return Err(Error::ParseConsoleInvalidModeGiven);
}
if parser.is_set("iobase") {
if let Some(iobase_opt) = parser.get("iobase") {
if !iobase_opt.starts_with("0x") {
return Err(Error::Validation(ValidationError::InvalidIoPortHex(
iobase_opt,
)));
}
iobase = Some(u16::from_str_radix(&iobase_opt[2..], 16).map_err(|_| {
if parser.is_set("iobase")
&& let Some(iobase_opt) = parser.get("iobase")
{
if !iobase_opt.starts_with("0x") {
return Err(Error::Validation(ValidationError::InvalidIoPortHex(
iobase_opt,
)));
}
iobase =
Some(u16::from_str_radix(&iobase_opt[2..], 16).map_err(|_| {
Error::Validation(ValidationError::InvalidIoPortHex(iobase_opt))
})?);
}
}
Ok(Self { file, mode, iobase })
@@ -1957,10 +1961,11 @@ impl DeviceConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
@@ -2000,12 +2005,12 @@ impl UserDeviceConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) {
return Err(ValidationError::IommuNotSupportedOnSegment(
self.pci_segment,
));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
{
return Err(ValidationError::IommuNotSupportedOnSegment(
self.pci_segment,
));
}
}
@@ -2062,10 +2067,11 @@ impl VdpaConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
@@ -2121,10 +2127,11 @@ impl VsockConfig {
return Err(ValidationError::InvalidPciSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref() {
if iommu_segments.contains(&self.pci_segment) && !self.iommu {
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
if let Some(iommu_segments) = platform_config.iommu_segments.as_ref()
&& iommu_segments.contains(&self.pci_segment)
&& !self.iommu
{
return Err(ValidationError::OnIommuSegment(self.pci_segment));
}
}
@@ -2493,10 +2500,10 @@ impl VmConfig {
{
let host_data_opt = &self.payload.as_ref().unwrap().host_data;
if let Some(host_data) = host_data_opt {
if host_data.len() != 64 {
return Err(ValidationError::InvalidHostData);
}
if let Some(host_data) = host_data_opt
&& host_data.len() != 64
{
return Err(ValidationError::InvalidHostData);
}
}
// The 'conflict' check is introduced in commit 24438e0390d3
@@ -2675,10 +2682,10 @@ impl VmConfig {
}
}
if let Some(vsock) = &self.vsock {
if [!0, 0, 1, 2].contains(&vsock.cid) {
return Err(ValidationError::VsockSpecialCid(vsock.cid));
}
if let Some(vsock) = &self.vsock
&& [!0, 0, 1, 2].contains(&vsock.cid)
{
return Err(ValidationError::VsockSpecialCid(vsock.cid));
}
if let Some(balloon) = &self.balloon {
@@ -3080,11 +3087,11 @@ impl VmConfig {
}
// Remove if vsock device
if let Some(vsock) = self.vsock.as_ref() {
if vsock.id.as_ref().map(|id| id.as_ref()) == Some(id) {
self.vsock = None;
removed = true;
}
if let Some(vsock) = self.vsock.as_ref()
&& vsock.id.as_ref().map(|id| id.as_ref()) == Some(id)
{
self.vsock = None;
removed = true;
}
removed