Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Clippy errors and warnings for Rust 1.75 #577

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.60
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: rustup component add clippy
- run: cargo clippy --all
Expand Down
2 changes: 1 addition & 1 deletion driver-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
#![allow(missing_docs)]
#![allow(non_camel_case_types)]

mod bindings;
pub mod bindings;
pub use self::bindings::*;
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
4 changes: 2 additions & 2 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ mod tests {

const TMP_DIR_STR: &str = "./tmp_sock_dir";

fn unset_envvar(varname: &String) {
let _ = unsafe {
fn unset_envvar(varname: &str) {
unsafe {
libc::unsetenv(varname.as_ptr() as *const c_char);
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/enclave_proc/connection_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {
const THREADS_STR: &str = "Threads:";
const TMP_DIR: &str = "./npe";

fn unset_envvar(varname: &String) {
fn unset_envvar(varname: &str) {
unsafe { libc::unsetenv(varname.as_ptr() as *const c_char) };
}

Expand Down Expand Up @@ -393,7 +393,7 @@ mod tests {
&mut cli_evt,
);

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

Expand Down
8 changes: 4 additions & 4 deletions src/enclave_proc/resource_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl ResourceAllocator {
// Always allocate larger pages first, to reduce fragmentation and page count.
// Once an allocation of a given page size fails, proceed to the next smaller
// page size and retry.
for (_, page_info) in HUGE_PAGE_MAP.iter().enumerate() {
for page_info in HUGE_PAGE_MAP.iter() {
while needed_mem >= page_info.1 as i64 {
match MemoryRegion::new(page_info.0) {
Ok(value) => {
Expand All @@ -389,7 +389,7 @@ impl ResourceAllocator {
// need to allocate in increasing order of page size in order to reduce wastage).

if needed_mem > 0 {
for (_, page_info) in HUGE_PAGE_MAP.iter().rev().enumerate() {
for page_info in HUGE_PAGE_MAP.iter().rev() {
while needed_mem > 0 {
match MemoryRegion::new(page_info.0) {
Ok(value) => {
Expand Down Expand Up @@ -420,7 +420,7 @@ impl ResourceAllocator {
.sort_by(|reg1, reg2| reg2.mem_size.cmp(&reg1.mem_size));

needed_mem = self.requested_mem as i64;
for (_, region) in self.mem_regions.iter().enumerate() {
for region in self.mem_regions.iter() {
if needed_mem <= 0 {
break;
}
Expand All @@ -434,7 +434,7 @@ impl ResourceAllocator {
self.mem_regions.drain(split_index..);

// Generate a summary of the allocated memory.
for (_, region) in self.mem_regions.iter().enumerate() {
for region in self.mem_regions.iter() {
if let Some(page_count) = allocated_pages.get_mut(&region.mem_size) {
*page_count += 1;
} else {
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