Skip to content

Commit

Permalink
Fix errors reported by Clippy (part 1 - automated)
Browse files Browse the repository at this point in the history
These changes are created automatically with `cargo clippy --fix
--allow-dirty`.

Signed-off-by: Costin Lupu <[email protected]>
  • Loading branch information
clupuishere committed Jan 8, 2024
1 parent a391c4e commit 8f40182
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 113 deletions.
20 changes: 10 additions & 10 deletions src/common/document_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Missing mandatory argument. User did not provide the `{}` argument.",
additional_info.get(0).unwrap_or(&info_placeholder)
additional_info.first().unwrap_or(&info_placeholder)
)
.as_str(),
);
Expand All @@ -93,7 +93,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Conflicting arguments. User provided both `{}` and `{}`.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder)
)
.as_str(),
Expand All @@ -103,7 +103,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Invalid argument provided. The parameter `{}` is not a valid integer (`{}`)",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder)
)
.as_str(),
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"\nFile: '{}', failing operation: '{}'.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder),
)
.as_str(),
Expand All @@ -171,7 +171,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Invalid CPU configuration. User provided `{}` contains same CPU(s) (CPU(s) {}) multiple times.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder),
)
.as_str(),
Expand All @@ -181,7 +181,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"No such CPU available in the pool. User provided `{}` contains CPU {}, which is not available in the pool.\nYou can add a specific CPU to the CPU pool by editing the `cpu_pool` value from '/etc/nitro_enclaves/allocator.yaml' and then enable the nitro-enclaves-allocator.service.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder),
).as_str(),
);
Expand All @@ -190,7 +190,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Insufficient CPUs available in the pool. User provided `{}` is {}, which is more than the configured CPU pool size.\nYou can increase the CPU pool size by editing the `cpu_count` value from '/etc/nitro_enclaves/allocator.yaml' and then enable the nitro-enclaves-allocator.service.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder),
).as_str(),
);
Expand All @@ -209,7 +209,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Insufficient memory requested. User provided `{}` is {} MB, but based on the EIF file size, the minimum memory should be {} MB",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder),
additional_info.get(2).unwrap_or(&info_placeholder)
).as_str(),
Expand All @@ -218,7 +218,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Insufficient memory requested. User provided `{}` is {} MB, and memory should be greater than 0 MB.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder)
).as_str(),
);
Expand All @@ -228,7 +228,7 @@ pub fn get_detailed_info(error_code_str: String, additional_info: &[String]) ->
ret.push_str(
format!(
"Insufficient memory available. User provided `{}` is {} MB, which is more than the available hugepage memory.\nYou can increase the available memory by editing the `memory_mib` value from '/etc/nitro_enclaves/allocator.yaml' and then restart the nitro-enclaves-allocator.service.",
additional_info.get(0).unwrap_or(&info_placeholder),
additional_info.first().unwrap_or(&info_placeholder),
additional_info.get(1).unwrap_or(&info_placeholder)
).as_str(),
);
Expand Down
8 changes: 4 additions & 4 deletions src/common/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ mod tests {
let _ = fs::remove_dir_all(tmp_log_dir);
} else {
// Only remove the log file
let _ = fs::remove_file(&format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME));
let _ = fs::remove_file(format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME));
}

// Reset old environment variable value if necessary
Expand All @@ -324,19 +324,19 @@ mod tests {
let _ = fs::create_dir(tmp_log_dir);

let log_writer = EnclaveProcLogWriter::new().unwrap();
let _ = log_writer.update_logger_id("new-logger-id").unwrap();
log_writer.update_logger_id("new-logger-id").unwrap();
let lock_result = log_writer.logger_id.lock();

assert!(lock_result.unwrap().eq("new-logger-id"));

let _ = log_writer.update_logger_id("").unwrap();
log_writer.update_logger_id("").unwrap();

if !path_existed {
// Remove whole `tmp_log_dir` if necessary
let _ = fs::remove_dir_all(tmp_log_dir);
} else {
// Only remove the log file
let _ = fs::remove_file(&format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME));
let _ = fs::remove_file(format!("{}/{}", tmp_log_dir, &LOG_FILE_NAME));
}

// Reset old environment variable value if necessary
Expand Down
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ mod tests {
const TMP_DIR_STR: &str = "./tmp_sock_dir";

fn unset_envvar(varname: &String) {
let _ = unsafe {
unsafe {
libc::unsetenv(varname.as_ptr() as *const c_char);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/enclave_proc/connection_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ mod tests {
&mut cli_evt,
);

assert_eq!(result.is_err(), true);
assert!(result.is_err());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/enclave_proc/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mod tests {
/// expected ones.
#[test]
fn test_enclaveprocsock_init() {
let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string());
let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID);

assert!(socket.is_ok());

Expand All @@ -260,7 +260,7 @@ mod tests {
/// trigger a `socket.requested_remove` change.
#[test]
fn test_start_monitoring() {
let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string());
let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID);

assert!(socket.is_ok());

Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {
/// that the listener thread joins.
#[test]
fn test_close() {
let socket = EnclaveProcSock::new(&DUMMY_ENCLAVE_ID.to_string());
let socket = EnclaveProcSock::new(DUMMY_ENCLAVE_ID);

assert!(socket.is_ok());

Expand Down
Loading

0 comments on commit 8f40182

Please sign in to comment.