From 5bf5de335065ffd45507f08312cdb69ab190d004 Mon Sep 17 00:00:00 2001 From: Jason Ish Date: Fri, 20 Aug 2021 10:59:41 -0600 Subject: [PATCH] rust(lint): don't use unwrap_or for function calls Calling a function in unwrap_or causes that function to always be called even when not needed. Instead use unwrap_or_else with a closure which will only be called when needed. --- rust/src/dcerpc/dcerpc.rs | 2 +- rust/src/smb/smb1_records.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 3f00e8312b..45b68a66d0 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -2149,7 +2149,7 @@ mod tests { .zip(expected_uuid) .map(|(x, y)| x.cmp(y)) .find(|&ord| ord != cmp::Ordering::Equal) - .unwrap_or(bind_uuid.len().cmp(&expected_uuid.len())) + .unwrap_or_else(|| bind_uuid.len().cmp(&expected_uuid.len())) ); } } diff --git a/rust/src/smb/smb1_records.rs b/rust/src/smb/smb1_records.rs index ec8f1f3052..5bc886532b 100644 --- a/rust/src/smb/smb1_records.rs +++ b/rust/src/smb/smb1_records.rs @@ -582,7 +582,7 @@ pub fn parse_smb_create_andx_request_record<'a>(i: &'a[u8], r: &SmbRecord) >> (SmbRequestCreateAndXRecord { disposition: disposition, create_options: create_options, - file_name: file_name.unwrap_or(Vec::new()), + file_name: file_name.unwrap_or_default(), })) }