Skip to content

Commit cf38285

Browse files
committed
Fix clippy warnings for hyperlight-guest
Signed-off-by: Mark Rossett <[email protected]>
1 parent 4417555 commit cf38285

File tree

7 files changed

+11
-36
lines changed

7 files changed

+11
-36
lines changed

Justfile

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,33 +176,6 @@ clippy-apply-fix-unix:
176176
clippy-apply-fix-windows:
177177
cargo clippy --target x86_64-pc-windows-msvc --fix --all
178178

179-
# Generate and test all possible feature combinations for a package
180-
clippy-feature-combinations package target=default-target:
181-
#!/usr/bin/env bash
182-
set -euo pipefail
183-
184-
# Get all features for the package
185-
features=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "{{package}}") | .features | keys[]' | grep -v default || true)
186-
187-
echo "Testing {{package}} with no features..."
188-
cargo clippy -p {{package}} --all-targets --no-default-features --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
189-
190-
echo "Testing {{package}} with default features..."
191-
cargo clippy -p {{package}} --all-targets --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings
192-
193-
# Test each feature individually
194-
for feature in $features; do
195-
echo "Testing {{package}} with feature: $feature"
196-
cargo clippy -p {{package}} --all-targets --no-default-features --features "$feature" --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings || echo "Feature $feature failed for {{package}}"
197-
done
198-
199-
# Test all features together
200-
if [ -n "$features" ]; then
201-
all_features=$(echo $features | tr '\n' ',' | sed 's/,$//')
202-
echo "Testing {{package}} with all features: $all_features"
203-
cargo clippy -p {{package}} --all-targets --no-default-features --features "$all_features" --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings || echo "All features failed for {{package}}"
204-
fi
205-
206179
# Run clippy with feature combinations for all packages
207180
clippy-exhaustive target=default-target: (witguest-wit)
208181
./hack/clippy-package-features.sh hyperlight-host {{ target }}

src/hyperlight_guest/src/guest_handle/handle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hyperlight_common::mem::HyperlightPEB;
2525
///
2626
/// Guests are expected to initialize this and store it. For example, you
2727
/// could store it in a global variable.
28-
#[derive(Debug, Clone, Copy)]
28+
#[derive(Debug, Clone, Copy, Default)]
2929
pub struct GuestHandle {
3030
peb: Option<*mut HyperlightPEB>,
3131
}

src/hyperlight_guest/src/guest_handle/host_comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ impl GuestHandle {
4141
let user_memory_region_size = unsafe { (*peb_ptr).init_data.size };
4242

4343
if num > user_memory_region_size {
44-
return Err(HyperlightGuestError::new(
44+
Err(HyperlightGuestError::new(
4545
ErrorCode::GuestError,
4646
format!(
4747
"Requested {} bytes from user memory, but only {} bytes are available",
4848
num, user_memory_region_size
4949
),
50-
));
50+
))
5151
} else {
5252
let user_memory_region_slice =
5353
unsafe { core::slice::from_raw_parts(user_memory_region_ptr, num as usize) };
@@ -142,7 +142,7 @@ impl GuestHandle {
142142
/// Write an error to the shared output data buffer.
143143
pub fn write_error(&self, error_code: ErrorCode, message: Option<&str>) {
144144
let guest_error: GuestError = GuestError::new(
145-
error_code.clone(),
145+
error_code,
146146
message.map_or("".to_string(), |m| m.to_string()),
147147
);
148148
let guest_error_buffer: Vec<u8> = (&guest_error)

src/hyperlight_guest_bin/src/exceptions/idtr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub(crate) unsafe fn load_idt() {
4949

5050
// Use &raw mut to get a mutable raw pointer, then dereference it
5151
// this is to avoid the clippy warning "shared reference to mutable static"
52+
#[allow(clippy::deref_addrof)]
5253
let idtr = &mut *(&raw mut IDTR);
5354
idtr.init(expected_base, idt_size as u16);
5455
idtr.load();

src/hyperlight_guest_bin/src/guest_function/call.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result<Vec<u8>
4242
// Find the function definition for the function call.
4343
// Use &raw const to get an immutable reference to the static HashMap
4444
// this is to avoid the clippy warning "shared reference to mutable static"
45+
#[allow(clippy::deref_addrof)]
4546
if let Some(registered_function_definition) =
4647
unsafe { (*(&raw const REGISTERED_GUEST_FUNCTIONS)).get(&function_call.function_name) }
4748
{
@@ -90,7 +91,7 @@ fn internal_dispatch_function() -> Result<()> {
9091
.expect("Function call deserialization failed");
9192

9293
let result_vec = call_guest_function(function_call).inspect_err(|e| {
93-
handle.write_error(e.kind.clone(), Some(e.message.as_str()));
94+
handle.write_error(e.kind, Some(e.message.as_str()));
9495
})?;
9596

9697
handle.push_shared_output_data(result_vec)

src/hyperlight_guest_bin/src/host_comm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn print_output_with_host_print(function_call: &FunctionCall) -> Result<Vec<
101101
pub unsafe extern "C" fn _putchar(c: c_char) {
102102
let handle = unsafe { GUEST_HANDLE };
103103
let char = c as u8;
104-
let mut message_buffer = unsafe { &mut MESSAGE_BUFFER };
104+
let message_buffer = unsafe { &mut MESSAGE_BUFFER };
105105

106106
// Extend buffer capacity if it's empty (like `with_capacity` in lazy_static).
107107
// TODO: replace above Vec::new() with Vec::with_capacity once it's stable in const contexts.
@@ -113,12 +113,12 @@ pub unsafe extern "C" fn _putchar(c: c_char) {
113113

114114
if message_buffer.len() == BUFFER_SIZE || char == b'\0' {
115115
let str = if char == b'\0' {
116-
CStr::from_bytes_until_nul(&message_buffer)
116+
CStr::from_bytes_until_nul(message_buffer)
117117
.expect("No null byte in buffer")
118118
.to_string_lossy()
119119
.into_owned()
120120
} else {
121-
String::from_utf8(mem::take(&mut message_buffer))
121+
String::from_utf8(mem::take(message_buffer))
122122
.expect("Failed to convert buffer to string")
123123
};
124124

src/hyperlight_guest_bin/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub extern "C" fn entrypoint(peb_address: u64, seed: u64, ops: u64, max_log_leve
104104
#[allow(static_mut_refs)]
105105
let peb_ptr = GUEST_HANDLE.peb().unwrap();
106106

107-
let srand_seed = ((peb_address << 8 ^ seed >> 4) >> 32) as u32;
107+
let srand_seed = (((peb_address << 8) ^ (seed >> 4)) >> 32) as u32;
108108

109109
// Set the seed for the random number generator for C code using rand;
110110
srand(srand_seed);

0 commit comments

Comments
 (0)