Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Make clippy a little bit happier #681

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions benchmarks/lucet-benchmarks/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn run_null<R: RegionCreate + 'static>(c: &mut Criterion) {
c.bench_function(&format!("run_null ({})", R::TYPE_NAME), move |b| {
b.iter_batched_ref(
|| region.new_instance(module.clone()).unwrap(),
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
});
Expand All @@ -224,7 +224,7 @@ fn run_fib<R: RegionCreate + 'static>(c: &mut Criterion) {
c.bench_function(&format!("run_fib ({})", R::TYPE_NAME), move |b| {
b.iter_batched_ref(
|| region.new_instance(module.clone()).unwrap(),
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
});
Expand Down Expand Up @@ -260,7 +260,7 @@ fn run_hello<R: RegionCreate + 'static>(c: &mut Criterion) {
.build()
.unwrap()
},
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
});
Expand Down Expand Up @@ -354,7 +354,7 @@ fn run_many_args<R: RegionCreate + 'static>(c: &mut Criterion) {
c.bench_function(&format!("run_many_args ({})", R::TYPE_NAME), move |b| {
b.iter_batched_ref(
|| region.new_instance(module.clone()).unwrap(),
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
});
Expand All @@ -373,7 +373,7 @@ fn run_hostcall_wrapped<R: RegionCreate + 'static>(c: &mut Criterion) {
move |b| {
b.iter_batched_ref(
|| region.new_instance(module.clone()).unwrap(),
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
},
Expand All @@ -391,7 +391,7 @@ fn run_hostcall_raw<R: RegionCreate + 'static>(c: &mut Criterion) {
c.bench_function(&format!("run_hostcall_raw ({})", R::TYPE_NAME), move |b| {
b.iter_batched_ref(
|| region.new_instance(module.clone()).unwrap(),
|inst| body(inst),
body,
criterion::BatchSize::PerIteration,
)
});
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/veriwasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl wasm_smith::Config for WasmSmithConfig {
fn build(with_veriwasm: bool, bytes: &[u8], tempdir: &TempDir, suffix: &str) -> Result<(), Error> {
let lucetc = Lucetc::try_from_bytes(bytes)?.with_veriwasm(with_veriwasm);
let so_file = tempdir.path().join(format!("out_{}.so", suffix));
lucetc.shared_object_file(so_file.clone())?;
lucetc.shared_object_file(so_file)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions lucet-module/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl Bindings {

pub fn from_str(s: &str) -> Result<Bindings, Error> {
let top: Value = serde_json::from_str(s)?;
Ok(Self::from_json(&top)?)
Self::from_json(&top)
}

pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Bindings, Error> {
let contents = fs::read_to_string(path.as_ref())?;
Ok(Self::from_str(&contents)?)
Self::from_str(&contents)
}

pub fn extend(&mut self, other: &Bindings) -> Result<(), Error> {
Expand Down
5 changes: 1 addition & 4 deletions lucet-module/src/linear_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,7 @@ impl OwnedSparseData {
SparseData::new(
self.pages
.iter()
.map(|c| match c {
Some(data) => Some(data.as_slice()),
None => None,
})
.map(|c| c.as_ref().map(|data| data.as_slice()))
.collect(),
)
.expect("SparseData invariant enforced by OwnedSparseData constructor")
Expand Down
8 changes: 3 additions & 5 deletions lucet-module/src/module_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,9 @@ impl OwnedModuleData {
/// `OwnedModuleData`.
pub fn to_ref<'a>(&'a self) -> ModuleData<'a> {
ModuleData::new(
if let Some(ref owned_linear_memory) = self.linear_memory {
Some(owned_linear_memory.to_ref())
} else {
None
},
self.linear_memory
.as_ref()
.map(|owned_linear_memory| owned_linear_memory.to_ref()),
self.globals_spec.iter().map(|gs| gs.to_ref()).collect(),
self.function_info
.iter()
Expand Down
8 changes: 4 additions & 4 deletions lucet-module/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ModuleSignature {
module_data: &ModuleData<'_>,
) -> Result<(), Error> {
let signature_box: SignatureBox =
SignatureBones::from_bytes(&module_data.get_module_signature())
SignatureBones::from_bytes(module_data.get_module_signature())
.map_err(ModuleSignatureError)?
.into();

Expand All @@ -30,7 +30,7 @@ impl ModuleSignature {
raw_module_and_data.patch_module_data(&cleared_module_data_bin);

minisign::verify(
&pk,
pk,
&signature_box,
Cursor::new(&raw_module_and_data.obj_bin),
true,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl RawModuleAndData {
}

pub fn patch_module_data(&mut self, module_data_bin: &[u8]) {
self.module_data_bin_mut().copy_from_slice(&module_data_bin);
self.module_data_bin_mut().copy_from_slice(module_data_bin);
}

pub fn write_patched_module_data<P: AsRef<Path>>(
Expand All @@ -130,7 +130,7 @@ impl RawModuleAndData {
.create_new(false)
.open(&path)?;
fp.seek(SeekFrom::Start(self.module_data_offset as u64))?;
fp.write_all(&patched_module_data_bin)?;
fp.write_all(patched_module_data_bin)?;
Ok(())
}

Expand Down
5 changes: 1 addition & 4 deletions lucet-module/src/version_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ mod test {
assert_eq!(v.patch, 6666);
assert_eq!(
v.version_hash,
[
'a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8, 'f' as u8, '1' as u8,
'2' as u8
]
[b'a', b'b', b'c', b'd', b'e', b'f', b'1', b'2']
);
}

Expand Down
2 changes: 1 addition & 1 deletion lucet-objdump/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn summarize_module<'a, 'b: 'a>(summary: &'a ArtifactSummary<'a>, module: &Modul

println!(" Start: {:#010x}", f.ptr().as_usize());
println!(" Code length: {} bytes", f.code_len());
if let Some(trap_manifest) = parse_trap_manifest(&summary, f) {
if let Some(trap_manifest) = parse_trap_manifest(summary, f) {
let trap_count = trap_manifest.traps.len();

println!(" Trap information:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn init_rejects_unaligned() {
let mut stack_unaligned = unsafe { slice::from_raw_parts_mut(ptr, len) };

// now we have the unaligned stack, let's make sure it blows up right
let res = ContextHandle::create_and_init(&mut stack_unaligned, dummy as usize, &[]);
let res = ContextHandle::create_and_init(stack_unaligned, dummy as usize, &[]);

if let Err(Error::UnalignedStack) = res {
assert!(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ extern "C" fn arg_printing_child(arg0: *mut c_void, arg1: *mut c_void) {
let arg0_val = unsafe { *(arg0 as *mut c_int) };
let arg1_val = unsafe { *(arg1 as *mut c_int) };

write!(
writeln!(
OUTPUT_STRING.lock().unwrap(),
"hello from the child! my args were {} and {}\n",
"hello from the child! my args were {} and {}",
arg0_val,
arg1_val
)
Expand All @@ -80,9 +80,9 @@ extern "C" fn arg_printing_child(arg0: *mut c_void, arg1: *mut c_void) {
let arg0_val = unsafe { *(arg0 as *mut c_int) };
let arg1_val = unsafe { *(arg1 as *mut c_int) };

write!(
writeln!(
OUTPUT_STRING.lock().unwrap(),
"now they are {} and {}\n",
"now they are {} and {}",
arg0_val,
arg1_val
)
Expand Down Expand Up @@ -133,9 +133,9 @@ fn call_child_twice() {
}

extern "C" fn context_set_child() {
write!(
writeln!(
OUTPUT_STRING.lock().unwrap(),
"hello from the child! setting context to parent...\n",
"hello from the child! setting context to parent...",
)
.unwrap();
unsafe {
Expand Down Expand Up @@ -168,9 +168,9 @@ fn call_child_setcontext_twice() {
}

extern "C" fn returning_child() {
write!(
writeln!(
OUTPUT_STRING.lock().unwrap(),
"hello from the child! returning...\n",
"hello from the child! returning...",
)
.unwrap();
}
Expand Down
8 changes: 4 additions & 4 deletions lucet-runtime/lucet-runtime-internals/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ impl Instance {
/// in the future.
pub fn run(&mut self, entrypoint: &str, args: &[Val]) -> Result<RunResult, Error> {
let func = self.module.get_export_func(entrypoint)?;
Ok(self.run_func(func, &args, false, None)?.unwrap())
Ok(self.run_func(func, args, false, None)?.unwrap())
}

/// Run a function with arguments in the guest context from the [WebAssembly function
Expand All @@ -532,7 +532,7 @@ impl Instance {
args: &[Val],
) -> Result<RunResult, Error> {
let func = self.module.get_func_from_idx(table_idx, func_idx)?;
Ok(self.run_func(func, &args, false, None)?.unwrap())
Ok(self.run_func(func, args, false, None)?.unwrap())
}

/// Resume execution of an instance that has yielded without providing a value to the guest.
Expand Down Expand Up @@ -1276,7 +1276,7 @@ impl Instance {
}
State::Terminating { details, .. } => {
self.state = State::Terminated;
Err(Error::RuntimeTerminated(details).into())
Err(Error::RuntimeTerminated(details))
}
State::Yielding { val, expecting } => {
self.state = State::Yielded { expecting };
Expand Down Expand Up @@ -1319,7 +1319,7 @@ impl Instance {
} else {
// leave the full fault details in the instance state, and return the
// higher-level info to the user
Err(Error::RuntimeFault(details).into())
Err(Error::RuntimeFault(details))
}
}
State::BoundExpired => {
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/lucet-runtime-internals/src/module/dl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl ModuleInternal for DlModule {
}

fn get_sparse_page_data(&self, page: usize) -> Option<&[u8]> {
if let Some(ref sparse_data) = self.module.module_data.sparse_data() {
if let Some(sparse_data) = self.module.module_data.sparse_data() {
*sparse_data.get_page(page)
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion lucet-runtime/lucet-runtime-internals/src/module/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl ModuleInternal for MockModule {
}

fn get_sparse_page_data(&self, page: usize) -> Option<&[u8]> {
if let Some(ref sparse_data) = self.module_data.sparse_data() {
if let Some(sparse_data) = self.module_data.sparse_data() {
*sparse_data.get_page(page)
} else {
None
Expand Down
9 changes: 5 additions & 4 deletions lucet-runtime/lucet-runtime-internals/src/region/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl RegionInternal for MmapRegion {
) -> Result<InstanceHandle, Error> {
let limits = self.get_limits();

module.validate_runtime_spec(&limits, heap_memory_size_limit)?;
module.validate_runtime_spec(limits, heap_memory_size_limit)?;

// Use the supplied alloc_strategy to get the next available slot
// for this new instance.
Expand Down Expand Up @@ -158,9 +158,10 @@ impl RegionInternal for MmapRegion {
.take()
.expect("alloc didn't have a slot during drop; dropped twice?");

if slot.heap as usize % host_page_size() != 0 {
panic!("heap is not page-aligned");
}
assert!(
!(slot.heap as usize % host_page_size() != 0),
"heap is not page-aligned"
);

// clear and disable access to the heap, stack, globals, and sigstack
for (ptr, len) in [
Expand Down
4 changes: 2 additions & 2 deletions lucet-runtime/lucet-runtime-internals/src/sysdeps/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ impl UContextPtr {

#[inline]
pub fn set_ip(self, new_ip: *const c_void) {
let mcontext: &mut mcontext64 = unsafe { &mut (*self.0).uc_mcontext.as_mut().unwrap() };
let mcontext: &mut mcontext64 = unsafe { (*self.0).uc_mcontext.as_mut().unwrap() };
mcontext.ss.rip = new_ip as u64;
}

#[inline]
pub fn set_rdi(self, new_rdi: u64) {
let mcontext: &mut mcontext64 = unsafe { &mut (*self.0).uc_mcontext.as_mut().unwrap() };
let mcontext: &mut mcontext64 = unsafe { (*self.0).uc_mcontext.as_mut().unwrap() };
mcontext.ss.rdi = new_rdi;
}
}
Expand Down
14 changes: 8 additions & 6 deletions lucet-runtime/tests/instruction_counting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ pub fn check_instruction_count_off() {
inst.run("test_function", &[]).expect("instance runs");

let instruction_count = inst.get_instruction_count();
if instruction_count.is_some() {
panic!("instruction count instrumentation was not expected from instance");
}
assert!(
!instruction_count.is_some(),
"instruction count instrumentation was not expected from instance"
);
});
}

Expand Down Expand Up @@ -177,9 +178,10 @@ fn check_instruction_count_with_periodic_yields_internal(want_start_function: bo
}
Poll::Pending => {
yields += 1;
if yields > 1000 {
panic!("Instruction-counting test ran for too long");
}
assert!(
!(yields > 1000),
"Instruction-counting test ran for too long"
);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions lucet-spectest/tests/wasm-spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ fn run_core_spec_test(name: &str) {
assert!(file.exists());
let run = lucet_spectest::run_spec_test(&file).unwrap();
run.report(); // Print to stdout
if !run.failed().is_empty() {
panic!("{} had {} failures", name, run.failed().len());
}
assert!(
run.failed().is_empty(),
"{} had {} failures",
name,
run.failed().len()
);
}

macro_rules! core_spec_test {
Expand Down
4 changes: 2 additions & 2 deletions lucet-wasi-fuzz/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ async fn run_both<P: AsRef<Path>>(
src: P,
seed: Option<Seed>,
) -> Result<TestResult, Error> {
let native_stdout = if let Some(stdout) = run_native(&tmpdir, src.as_ref())? {
let native_stdout = if let Some(stdout) = run_native(tmpdir, src.as_ref())? {
stdout
} else {
return Ok(TestResult::Ignored);
};

let (exitcode, wasm_stdout) = run_with_stdout(&tmpdir, src.as_ref()).await?;
let (exitcode, wasm_stdout) = run_with_stdout(tmpdir, src.as_ref()).await?;

assert_eq!(exitcode, 0);

Expand Down
6 changes: 3 additions & 3 deletions lucet-wasi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ async fn main() {
let heap_memory_size = matches
.value_of("heap_memory_size")
.ok_or_else(|| format_err!("missing heap memory size"))
.and_then(|v| parse_humansized(v))
.and_then(parse_humansized)
.unwrap() as usize;

let heap_address_space_size = matches
.value_of("heap_address_space_size")
.ok_or_else(|| format_err!("missing heap address space size"))
.and_then(|v| parse_humansized(v))
.and_then(parse_humansized)
.unwrap() as usize;

if heap_memory_size > heap_address_space_size {
Expand All @@ -173,7 +173,7 @@ async fn main() {
let stack_size = matches
.value_of("stack_size")
.ok_or_else(|| format_err!("missing stack size"))
.and_then(|v| parse_humansized(v))
.and_then(parse_humansized)
.unwrap() as usize;

let timeout = matches
Expand Down
Loading