misc: clippy: add manual_string_new

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-11-18 12:27:30 +01:00
committed by Rob Bradford
parent b4c62bf159
commit fed010fcd1
5 changed files with 15 additions and 14 deletions

View File

@@ -171,6 +171,7 @@ suspicious = "deny"
# Individual Lints # Individual Lints
assertions_on_result_states = "deny" assertions_on_result_states = "deny"
manual_string_new = "deny"
semicolon_if_nothing_returned = "deny" semicolon_if_nothing_returned = "deny"
undocumented_unsafe_blocks = "deny" undocumented_unsafe_blocks = "deny"
uninlined_format_args = "deny" uninlined_format_args = "deny"

View File

@@ -26,10 +26,10 @@ impl<T: Debug> Display for Exception<T> {
self.ip, self.ip,
self.error self.error
.map(|e| format!(": error {e:x}")) .map(|e| format!(": error {e:x}"))
.unwrap_or_else(|| "".to_owned()), .unwrap_or_default(),
self.payload self.payload
.map(|payload| format!(": payload {payload:x}")) .map(|payload| format!(": payload {payload:x}"))
.unwrap_or_else(|| "".to_owned()) .unwrap_or_default()
) )
} }
} }

View File

@@ -48,7 +48,7 @@ pub struct MetricsReport {
impl Default for MetricsReport { impl Default for MetricsReport {
fn default() -> Self { fn default() -> Self {
let mut git_human_readable = "".to_string(); let mut git_human_readable = String::new();
if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() { if let Ok(git_out) = Command::new("git").args(["describe", "--dirty"]).output() {
if git_out.status.success() { if git_out.status.success() {
git_human_readable = String::from_utf8(git_out.stdout) git_human_readable = String::from_utf8(git_out.stdout)
@@ -63,7 +63,7 @@ impl Default for MetricsReport {
} }
} }
let mut git_revision = "".to_string(); let mut git_revision = String::new();
if let Ok(git_out) = Command::new("git").args(["rev-parse", "HEAD"]).output() { if let Ok(git_out) = Command::new("git").args(["rev-parse", "HEAD"]).output() {
if git_out.status.success() { if git_out.status.success() {
git_revision = String::from_utf8(git_out.stdout) git_revision = String::from_utf8(git_out.stdout)
@@ -78,7 +78,7 @@ impl Default for MetricsReport {
} }
} }
let mut git_commit_date = "".to_string(); let mut git_commit_date = String::new();
if let Ok(git_out) = Command::new("git") if let Ok(git_out) = Command::new("git")
.args(["show", "-s", "--format=%cd"]) .args(["show", "-s", "--format=%cd"])
.output() .output()

View File

@@ -1237,7 +1237,7 @@ fn test_vhost_user_net(
if let Some(host_mac) = host_mac { if let Some(host_mac) = host_mac {
format!(",host_mac={host_mac}") format!(",host_mac={host_mac}")
} else { } else {
"".to_owned() String::new()
}, },
if client_mode_daemon { if client_mode_daemon {
"server" "server"
@@ -1636,7 +1636,7 @@ fn _test_virtio_fs(
if let Some(pci_segment) = pci_segment { if let Some(pci_segment) = pci_segment {
format!(",pci_segment={pci_segment}") format!(",pci_segment={pci_segment}")
} else { } else {
"".to_owned() String::new()
} }
); );
@@ -1730,7 +1730,7 @@ fn _test_virtio_fs(
if let Some(pci_segment) = pci_segment { if let Some(pci_segment) = pci_segment {
format!(",pci_segment={pci_segment}") format!(",pci_segment={pci_segment}")
} else { } else {
"".to_owned() String::new()
} }
); );
@@ -2019,7 +2019,7 @@ fn _get_vmm_overhead(pid: u32, guest_memory_size: u32) -> HashMap<String, u32> {
let reader = io::BufReader::new(smaps); let reader = io::BufReader::new(smaps);
let mut skip_map: bool = false; let mut skip_map: bool = false;
let mut region_name: String = "".to_string(); let mut region_name: String = String::new();
let mut region_maps = HashMap::new(); let mut region_maps = HashMap::new();
for line in reader.lines() { for line in reader.lines() {
let l = line.unwrap(); let l = line.unwrap();
@@ -5977,7 +5977,7 @@ mod common_parallel {
if let Some(pci_segment) = pci_segment { if let Some(pci_segment) = pci_segment {
format!(",pci_segment={pci_segment}") format!(",pci_segment={pci_segment}")
} else { } else {
"".to_owned() String::new()
} }
)), )),
); );
@@ -6109,7 +6109,7 @@ mod common_parallel {
if let Some(pci_segment) = pci_segment { if let Some(pci_segment) = pci_segment {
format!(",pci_segment={pci_segment}") format!(",pci_segment={pci_segment}")
} else { } else {
"".to_owned() String::new()
} }
) )
.as_str(), .as_str(),
@@ -6172,7 +6172,7 @@ mod common_parallel {
if let Some(pci_segment) = pci_segment { if let Some(pci_segment) = pci_segment {
format!(",pci_segment={pci_segment}") format!(",pci_segment={pci_segment}")
} else { } else {
"".to_owned() String::new()
} }
) )
.as_str(), .as_str(),

View File

@@ -4681,7 +4681,7 @@ mod unit_tests {
// Test empty string serial (should be valid) // Test empty string serial (should be valid)
let mut empty_serial_config = valid_config.clone(); let mut empty_serial_config = valid_config.clone();
empty_serial_config.disks = Some(vec![DiskConfig { empty_serial_config.disks = Some(vec![DiskConfig {
serial: Some("".to_string()), serial: Some(String::new()),
..disk_fixture() ..disk_fixture()
}]); }]);
empty_serial_config.validate().unwrap(); empty_serial_config.validate().unwrap();
@@ -4755,7 +4755,7 @@ mod unit_tests {
#[cfg(feature = "igvm")] #[cfg(feature = "igvm")]
igvm: None, igvm: None,
#[cfg(feature = "sev_snp")] #[cfg(feature = "sev_snp")]
host_data: Some("".to_string()), host_data: Some(String::new()),
#[cfg(feature = "fw_cfg")] #[cfg(feature = "fw_cfg")]
fw_cfg_config: None, fw_cfg_config: None,
}); });